NITK06 - MODIFY SEQUENCE

Suppose we have a sequence of non-negative integers, Namely a1, a2 ... an. At each time we can choose one term ai with 0 < i < n and we subtract 1 from both ai and ai+1. We wonder whether we can get a sequence of all zeros after several operations.

Input

The first line is the number of test cases T (0 < T ≤ 20).

The first line of each test case is a number N (0 < N ≤ 10000). The next line is N non-negative integers, 0 ≤ ai ≤ 109.

Output

If it can be modified into all zeros with several operations output “YES” in a single line, otherwise output “NO” instead.

Example

Input:
2
2
1 2
2
2 2

Output:
NO
YES

Explanation

It is clear that [1 2] can be reduced to [0 1] but no further to convert all integers to 0. Hence, the output is NO.

In second case, output is YES as [2 2] can be reduced to [1 1] and then to [0 0] in just two steps.


Added by:Gaurav Jain
Date:2013-09-25
Time limit:0.5s-1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64

hide comments
2024-03-19 02:15:01
[More test cases]

7
8
0 1 3 2 2 3 1 0
2
1 2
2
2 2
6
0 1 3 2 1 1
5
0 4 2 0 2
5
1 2 1 1 1
4
1 2 1 1

[My output]

YES
NO
YES
YES
NO
YES
NO
2020-09-05 10:45:18
how can 0 4 2 0 2 give yes?
2020-01-30 21:20:25
Quite simple!!!!!
2018-06-15 07:41:38
#very_weak_test_cases... ;)

Last edit: 2018-06-15 07:42:40
2018-05-28 21:44:05
wrong answer accepted
2018-04-01 22:06:12
Okay so the test cases are extremly weak. And I wouldn't have even realized if it were not for the comments. Thanks all!
Be sure to run your code on
1
5
0 4 2 0 2
before moving on to the next question
2018-03-29 14:35:55
we can do this problem..... without using an array,ie O(1) space
2018-03-29 14:35:55
we can do this problem..... without using an array,ie O(1) space
2018-01-15 16:47:42
size of array costed me many WAs
2017-12-26 18:00:55
AC in One Go !!
Easy One.

Last edit: 2017-12-26 18:05:53
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.