CF1941B.Rudolf and 121

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Rudolf and 121

Rudolf has an array aa of nn integers, the elements are numbered from 11 to nn.

In one operation, he can choose an index ii (2in12 \le i \le n - 1) and assign:

  • ai1=ai11a_{i - 1} = a_{i - 1} - 1
  • ai=ai2a_i = a_i - 2
  • ai+1=ai+11a_{i + 1} = a_{i + 1} - 1

Rudolf can apply this operation any number of times. Any index ii can be used zero or more times.

Can he make all the elements of the array equal to zero using this operation?

Input

The first line of the input contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases in the test.

The first line of each case contains a single integer nn (3n21053 \le n \le 2 \cdot 10^5) — the number of elements in the array.

The second line of each case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (0aj1090 \le a_j \le 10^9) — the elements of the array.

It is guaranteed that the sum of the values of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output "YES" if it is possible to make all the elements of the array zero using the described operations. Otherwise, output "NO".

You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.

Note

In the first example, the original array is [1,3,5,5,2][1, 3, 5, 5, 2], to make all its elements zero, Rudolf can act as follows:

  • apply the operation at i=4i=4 and get the array [1,3,4,3,1][1, 3, 4, 3, 1];
  • apply the operation at i=3i=3 and get the array [1,2,2,2,1][1, 2, 2, 2, 1];
  • apply the operation at i=2i=2 and get the array [0,0,1,2,1][0, 0, 1, 2, 1];
  • apply the operation at i=4i=4 and get the array [0,0,0,0,0][0, 0, 0, 0, 0].

Samples

7
5
1 3 5 5 2
5
2 4 4 5 1
5
0 1 3 3 1
6
5 6 0 2 3 0
4
1 2 7 2
3
7 1 0
4
1 1 1 1
YES
NO
YES
NO
NO
NO
NO

在线编程 IDE

建议全屏模式获得最佳体验