P17665 [IO 2025 #3] LOIS

Description

Just as she was about to solve the mystery of what LOIS really is, Wednesday entered a room with a single door. An array is written on the door, whose elements are all integers between $0$ and $k$, inclusive. Uncle Fester told her that to open the door, she needs to come up with another array, different from the given one, whose elements are also integers between $0$ and $k$, and which is "similar" to the given array. Uncle Fester considers two arrays "similar" if and only if the sums of their elements are equal and the products of their elements are also equal. Find an array that is different from the original one but similar to it, or report that no solution exists.

Input Format

The first line contains two integers $n,k$: the length of the array on the door and the upper bound of the element values, satisfying $1\le n,k\le 10^5$. The second line contains $n$ integers $a_1,\ldots,a_n$, the elements of the array, satisfying $0\le a_i\le k$.

Output Format

If no array satisfies the requirements, output $-1$; in this case Wednesday cannot open the door. Otherwise, in the first line output an integer $m$, the length of the desired array, satisfying $1\le m\le 3\cdot 10^5$. In the second line output $m$ integers between $0$ and $k$, the array that solves the puzzle.

Explanation/Hint

Translated by QwenWork