CF BUDDY
← Problems·

1991C · Absolute Zero

1300 · constructive algorithms, greedy, math

Problem: You are given an array aa of nn integers.

In one operation, you will perform the following two-step move:

  1. Choose an integer xx (0x1090 \le x \le 10^{9}).
  2. Replace each aia_i with aix|a_i - x|, where v|v| denotes the absolute value of vv.

For example, by choosing x=8x = 8, the array [5,7,10][5, 7, 10] will be changed into [58,78,108]=[3,1,2][|5-8|, |7-8|, |10-8|] = [3,1,2].

Construct a sequence of operations to make all elements of aa equal to 00 in at most 4040 operations or determine that it is impossible. You do not need to minimize the number of operations.

Input Format: Each test contains multiple test cases. The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (1n21051 \le n \le 2 \cdot 10^5) — the length of the array aa.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai1090 \le a_i \le 10^9) — the elements of the array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output Format: For each test case, output a single integer 1-1 if it is impossible to make all array elements equal to 00 in at most 4040 operations.

Otherwise, output two lines. The first line of output should contain a single integer kk (0k400 \le k \le 40) — the number of operations. The second line of output should contain kk integers x1,x2,,xkx_1, x_2, \ldots, x_k (0xi1090 \le x_i \le 10^{9}) — the sequence of operations, denoting that on the ii-th operation, you chose x=xix=x_i.

If there are multiple solutions, output any of them.

You do not need to minimize the number of operations.

Note: In the first test case, we can perform only one operation by choosing x=5x = 5, changing the array from [5][5] to [0][0].

In the second test case, no operations are needed because all elements of the array are already 00.

In the third test case, we can choose x=6x = 6 to change the array from [4,6,8][4, 6, 8] to [2,0,2][2, 0, 2], then choose x=1x = 1 to change it to [1,1,1][1, 1, 1], and finally choose x=1x = 1 again to change the array into [0,0,0][0, 0, 0].

In the fourth test case, we can make all elements 00 by following the operation sequence (60,40,20,10,30,25,5)(60, 40, 20, 10, 30, 25, 5).

In the fifth test case, it can be shown that it is impossible to make all elements 00 in at most 4040 operations. Therefore, the output is 1-1.

Sample Cases

Case 1

Input

5
1
5
2
0 0
3
4 6 8
4
80 40 20 10
5
1 2 3 4 5

Output

1
5
0

3
6 1 1
7
60 40 20 10 30 25 5
-1

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback