Triple Fold
Jamie, being separated from the safari tour group, has been enticed by a scheming hyena to play a game for money. The hyena gives Jamie stones, each with a non-negative integer scratched into it with the hyena's claws.
In one operation, Jamie may choose a non-negative integer and simultaneously replace all stone values by
.
Jamie may perform this operation up to 3 times, and he wants to make all stones show the same number. As soon as all stones show the same number, the game immediately ends; Jamie cannot perform any further operations after that point. For example, if all stones are already equal, Jamie performs operations.
If it is possible to make all stones equal, Jamie wants to produce a valid sequence of operations that results in the smallest possible final value.
Thus, for each of the cases given by the hyena:
- output the minimum possible final value,
- output any sequence of pivots (the values of each
),
- or report that it is impossible.
Input
The first line contains a single integer (
), the number of test cases.
Each test case contains two lines:
- a single integer
(
), the number of stones given in this case, and
space-separated integers
(
), the value of each stone.
The sum of over all test cases does not exceed
.
Output
For each test case, output -1 if it is impossible to make the stones all have the same value before the game ends.
Otherwise, output two integers v k, where is the minimum possible final value and
is the number of operations used.
On the next line, output the pivots in order. If
, output a blank line.
Any valid sequence achieving the minimum final value is accepted.
Example
Input 1
3
2
1 3
4
0 2 4 8
2
0 1
Output 1
1 1
2
1 3
1 4 2
-1
Explanation 1
In the first case, choosing changes the stones to
. The game then ends immediately.
In the second case, the pivots change the stones as follows:
0 2 4 8 -> 1 1 3 7 -> 3 3 1 3 -> 1 1 1 1.
It is possible to make all stones equal, and the minimum final value is .
In the third case, the two stones have values and
. Their difference remains odd after every operation, so they can never become equal.
Input 2
1
3
67 67 67
Output 2
67 0
Explanation 2
The stones are already equal, so Jamie performs no operations and the final value is .
Input 3
1
4
0 4 6 10
Output 3
1 3
2 5 2
Explanation 3
These operations produces the following arrays: 0 4 6 10 -> 2 2 4 8 -> 3 3 1 3 -> 1 1 1 1.
Note that it is possible to produce an array of all twos with just two operations via operations 5 3. It is important to note that we are looking for the operations that produce the minimum final element among all valid sets, not minimising the amount of operations.
Comments