#d1304. 整齐的数组2
整齐的数组2
Neat Array 2
Problem Description
Polycarp has an array of length (where is even). Polycarp is also given a positive integer , and he starts performing the following operation on : choose an index () and subtract from .
After Polycarp performs some number of operations (possibly zero), at least half of the elements in become equal. Find the largest valid ; if can be arbitrarily large, output .
Input Format
The first line contains an integer , the number of test cases.
Each test case then has two lines. The first contains an even integer . The second contains integers .
Output Format
For each test case, output a single integer () on its own line — the largest number Polycarp can use to perform operations on the array — or if can be arbitrarily large.
Sample Input
4
6
48 13 22 -15 16 35
8
-1 0 1 -1 0 1 -1 0
4
100 -1000 -1000 -1000
4
1 1 1 1
Sample Output
13
2
-1
-1
Constraints
For all data, , (with even), , and the sum of all does not exceed .