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
2017-09-25 17:23:50
Wrong Test cases. It is not supposed to accept the sequence 0 4 2 0 2. As it is not possible to reduce down the sequence into the one with all entries zero. But it is accepting my code which accepts this sequence. :(
Simply calculating sum is not all the question wants. Correct me, if i'm wrong. :)
2017-06-18 11:29:56
think simple just do what question say :P
2017-04-05 02:14:39
I wonder, what would constitute "strong" test cases? This is a very easy problem.
2017-01-12 15:05:51
Weak Test cases....wrong solution gets accepted.
2016-12-08 14:48:06
AC in one go... !!
simple one
2016-11-11 06:08:38
Ankit Jain teriii maa ki choot ...... aise question karega to tcs me kaise jayega ????
2016-10-19 13:25:29
Consider the case for n=1 :P
2016-01-25 16:15:32 minhthai
nice problem, think opposite :)
2015-12-08 17:11:39
nice problem but weak test cases
2015-08-19 09:01:56 SangKuan
brute force, want to know is there has other better way
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.