Codeforces Round 874 (Div. 3) C. Vlad Building Beautiful Array

Vlad was given an array a of n positive integers. Now he wants to build a beautiful array b of length n from it.

Vlad considers an array beautiful if all the numbers in it are positive and have the same parity. That is, all numbers in the beautiful array are greater than zero and are either all even or all odd.

To build the array b, Vlad can assign each bi either the value ai or ai−aj, where any j from 1 to n can be chosen.

To avoid trying to do the impossible, Vlad asks you to determine whether it is possible to build a beautiful array b of length n using his array a.

Input

The first line of input contains an integer t (1≤t≤104) — the number of test cases.

Then follow the descriptions of the test cases.

The first line of each case contains a single integer n (1≤n≤2⋅105) — the length of the array a.

The second line of each case contains n positive integers a1,a2,…,an (1≤ai≤109) — the elements of the array a.

It is guaranteed that the sum of n over all cases does not exceed 2⋅1052⋅105.

Output

Output t strings, each of which is the answer to the corresponding test case. As the answer, output "YES" if Vlad can build a beautiful array b, and "NO" otherwise.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

Example

input

7

5

2 6 8 4 3

5

1 4 7 6 9

4

2 6 4 10

7

5 29 13 9 10000001 11 3

5

2 1 2 4 2

5

2 4 5 4 3

4

2 5 5 4

output

NO
YES
YES
YES
YES
NO
NO

题意:给一个数组a,现在能否可以构建出一个等长度的数组b,使得b中各个数的奇偶性相同且都大于0,且b中的项bi为ai,或者等于ai-aj,j为1-n任意的值。

由于一个数只有减去奇数才可以改变奇偶性,所以我们可以找出最小的奇数。如果a数组每个数的奇偶性相同,则满足题意。若不同,就让a数组中每一个偶数减去最小的奇数,若每个值均大于0,则满足题意。

#include
using namespace std;
int a[200001];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
	int minn=0x3f3f3f3f;
	int cnt=0;
	for(int i=0;i>a[i];
		if(a[i]&1)
		{
			cnt++;
			minn=min(a[i],minn);
		}
	}
	if(cnt==n||cnt==0)
	cout<<"YES"<

你可能感兴趣的:(c++,算法)