Vlad Building Beautiful Array solution codeforces

Vlad Building Beautiful Array solution codeforces

Vlad was given an array 𝑎 of 𝑛 positive integers. Now he wants to build a beautiful array 𝑏 of length 𝑛 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 𝑏, Vlad can assign each 𝑏𝑖�� either the value 𝑎𝑖�� or 𝑎𝑖𝑎𝑗��−��, where any 𝑗 from 11 to 𝑛 can be chosen.

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

Vlad Building Beautiful Array solution codeforces

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

Then follow the descriptions of the test cases.

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

The second line of each case contains 𝑛 positive integers 𝑎1,𝑎2,,𝑎𝑛�1,�2,…,�� (1𝑎𝑖1091≤��≤109) — the elements of the array 𝑎.

It is guaranteed that the sum of 𝑛 over all cases does not exceed 21052⋅105.

Output

Output 𝑡 strings, each of which is the answer to the corresponding test case. As the answer, output “YES” if Vlad can build a beautiful array 𝑏, 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

Copy
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

Copy
NO
YES
YES
YES
YES
NO
NO

 

Leave a Reply

Your email address will not be published. Required fields are marked *