311146: CF1941B. Rudolf and 121

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Rudolf and 121time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Rudolf has an array $a$ of $n$ integers, the elements are numbered from $1$ to $n$.

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

  • $a_{i - 1} = a_{i - 1} - 1$
  • $a_i = a_i - 2$
  • $a_{i + 1} = a_{i + 1} - 1$

Rudolf can apply this operation any number of times. Any index $i$ 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 $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.

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

The second line of each case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_j \le 10^9$) — the elements of the array.

It is guaranteed that the sum of the values of $n$ over all test cases does not exceed $2 \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.

ExampleInput
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
Output
YES
NO
YES
NO
NO
NO
NO
Note

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

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

Output

题目大意:
鲁道夫有一个由n个整数组成的数组a,元素从1到n编号。通过一次操作,他可以选择一个索引i(2≤i≤n-1)并赋值:
- a_{i-1} = a_{i-1} - 1
- a_i = a_i - 2
- a_{i+1} = a_{i+1} - 1
鲁道夫可以任意次数地应用此操作。任何索引i都可以使用零次或多次。问他能否使用此操作使数组的所有元素等于零。

输入数据格式:
输入的第一行包含一个整数t(1≤t≤10^4)——测试用例的数量。
每个案例的第一行包含一个整数n(3≤n≤2×10^5)——数组中的元素数量。
每个案例的第二行包含n个整数a_1, a_2, …, a_n(0≤a_j≤10^9)——数组的元素。
保证所有测试案例的n值之和不超过2×10^5。

输出数据格式:
对于每个测试案例,如果可以通过描述的操作使数组的所有元素为零,则输出“YES”。否则输出“NO”。
输出每个字母的大小写均可。例如,字符串“yEs”、“yes”、“Yes”和“YES”都将被接受为肯定回答。

例:
输入:
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

注意:
在第一个例子中,原始数组是[1, 3, 5, 5, 2],为了使所有元素为零,鲁道夫可以按如下方式操作:
- 在i=4处应用操作,得到数组[1, 3, 4, 3, 1];
- 在i=3处应用操作,得到数组[1, 2, 2, 2, 1];
- 在i=2处应用操作,得到数组[0, 0, 1, 2, 1];
- 在i=4处应用操作,得到数组[0, 0, 0, 0, 0]。题目大意: 鲁道夫有一个由n个整数组成的数组a,元素从1到n编号。通过一次操作,他可以选择一个索引i(2≤i≤n-1)并赋值: - a_{i-1} = a_{i-1} - 1 - a_i = a_i - 2 - a_{i+1} = a_{i+1} - 1 鲁道夫可以任意次数地应用此操作。任何索引i都可以使用零次或多次。问他能否使用此操作使数组的所有元素等于零。 输入数据格式: 输入的第一行包含一个整数t(1≤t≤10^4)——测试用例的数量。 每个案例的第一行包含一个整数n(3≤n≤2×10^5)——数组中的元素数量。 每个案例的第二行包含n个整数a_1, a_2, …, a_n(0≤a_j≤10^9)——数组的元素。 保证所有测试案例的n值之和不超过2×10^5。 输出数据格式: 对于每个测试案例,如果可以通过描述的操作使数组的所有元素为零,则输出“YES”。否则输出“NO”。 输出每个字母的大小写均可。例如,字符串“yEs”、“yes”、“Yes”和“YES”都将被接受为肯定回答。 例: 输入: 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 注意: 在第一个例子中,原始数组是[1, 3, 5, 5, 2],为了使所有元素为零,鲁道夫可以按如下方式操作: - 在i=4处应用操作,得到数组[1, 3, 4, 3, 1]; - 在i=3处应用操作,得到数组[1, 2, 2, 2, 1]; - 在i=2处应用操作,得到数组[0, 0, 1, 2, 1]; - 在i=4处应用操作,得到数组[0, 0, 0, 0, 0]。

加入题单

上一题 下一题 算法标签: