题目描述
Chef has an array A of length N.
Chef forms a binary array B of length N using the parity of the sums of adjacent elements in A. Formally,
B_{i} = (A_{i} + A_{i+1}) \, \% \, 2 for 1 ≤ i ≤ N - 1
B_{N} = (A_{N} + A_{1}) \, \% \, 2
Here x \, \% \, y denotes the remainder obtained when x is divided by y.
Chef lost the array A and needs your help. Given array B, determine whether there exits any valid array A which could have formed B.
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N — the size of the array A.
- The second line of each test case contains $N space-separated integers B_{1}, B_{2}, \dots, B_{N}$ denoting the array B.
------ Output Format ------
For each testcase, output YES if there exists a valid array A, NO otherwise.
You can print any character in any case. For example YES, Yes, yEs are all considered same.
------ Constraints ------
$1 ≤ T ≤ 1000$
$2 ≤ N ≤ 10^{5}$
$B_{i} \in \{0, 1\}$
- The sum of $N$ over all test cases do not exceed $3 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
0 0
2
1 0
4
1 0 1 0
3
1 0 0
----- Sample Output 1 ------
YES
NO
YES
NO
----- explanation 1 ------
Test case 1: One such valid array is $A = [3, 3]$.
Test case 2: It can be shown that no such arrays exist and are valid.
Test case 3: One such valid array is $A = [1, 2, 4, 5]$.
- $B_{1} = 1$ since $A_{1} + A_{2} = 1 + 2 = 3$ and $3 \, \% \, 2 = 1$
- $B_{2} = 0$ since $A_{2} + A_{3} = 2 + 4 = 6$ and $6 \, \% \, 2 = 0$
- $B_{3} = 1$ since $A_{3} + A_{4} = 4 + 5 = 9$ and $9 \, \% \, 2 = 1$
- $B_{4} = 0$ since $A_{4} + A_{1} = 5 + 1 = 6$ and $6 \, \% \, 2 = 0$
输入格式
见题面
输出格式
见题面