题目描述
You are given N integers ${A_{1}, A_{2}, \ldots, A_{N}$}. Determine whether they can be reordered such that each pair of consecutive differences differ by a factor of 2.
Formally, determine whether there exists a rearrangement of the given integers into an array $[B_{1}, B_{2}, \ldots, B_{N}]$ such that, for each 2 ≤ i ≤ N-1, at least one of the following two conditions holds:
$B_{i} - B_{i-1} = 2\cdot (B_{i+1} - B_{i}), *$or*
$2\cdot (B_{i} - B_{i-1}) = B_{i+1} - B_{i}$
Note that different conditions can hold at different indices — the only restriction is that at each index, at least one of the given conditions must hold. Please see the sample tests below for examples.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer, N.
- The second line of each test case contains $N space-separated integers, denoting A_{1}, A_{2}, \ldots, A_{N}$.
------ Output Format ------
For each test case, output in a single line the answer — $\texttt{YES}$ if a rearrangement that satisfies the given conditions exists, and $\texttt{NO}$ otherwise.
The output is not case sensitive, so for example the strings $\texttt{YES, Yes, yES},$ etc. will all be treated as correct.
------ Constraints ------
$1 ≤ T ≤ 100$
$3 ≤ N ≤ 10^{5}$
$0 ≤ A_{i} ≤ 10^{9}$
- The sum of $N$ across all test cases won't exceed $10^{5}$
----- Sample Input 1 ------
4
3
5 2 4
5
2 1 16 8 4
5
97 98 100 96 88
6
16 19 18 21 24 22
----- Sample Output 1 ------
Yes
Yes
No
Yes
----- explanation 1 ------
Test case $1$: Rearrange the numbers to form $[5, 4, 2]$. The consecutive differences are $[4-5, 2-4] = [-1, -2]$, and $-2 = 2\cdot (-1)$.
Test case $2$: One possible rearrangement is $[1, 2, 4, 8, 16]$. The consecutive differences are consecutive powers of $2$.
Test case $3$: No rearrangement of the numbers satisfies the condition. For example, one rearrangement is $[97, 98, 100, 96, 88]$ with consecutive differences $[1, 2, -4, -8]$. $2$ and $-4$ do not differ by a factor of $2$ (they differ by a factor of $-2$), so this is not a valid arrangement.
输入格式
见题面
输出格式
见题面