CF1324A.Yet Another Tetris Problem

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

Yet Another Tetris Problem

You are given some Tetris field consisting of nn columns. The initial height of the ii-th column of the field is aia_i blocks. On top of these columns you can place only figures of size 2×12 \times 1 (i.e. the height of this figure is 22 blocks and the width of this figure is 11 block). Note that you cannot rotate these figures.

Your task is to say if you can clear the whole field by placing such figures.

More formally, the problem can be described like this:

The following process occurs while at least one aia_i is greater than 00:

  1. You place one figure 2×12 \times 1 (choose some ii from 11 to nn and replace aia_i with ai+2a_i + 2);
  2. then, while all aia_i are greater than zero, replace each aia_i with ai1a_i - 1.

And your task is to determine if it is possible to clear the whole field (i.e. finish the described process), choosing the places for new figures properly.

You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1t1001 \le t \le 100) — the number of test cases.

The next 2t2t lines describe test cases. The first line of the test case contains one integer nn (1n1001 \le n \le 100) — the number of columns in the Tetris field. The second line of the test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1001 \le a_i \le 100), where aia_i is the initial height of the ii-th column of the Tetris field.

Output

For each test case, print the answer — "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise.

Note

The first test case of the example field is shown below:

Gray lines are bounds of the Tetris field. Note that the field has no upper bound.

One of the correct answers is to first place the figure in the first column. Then after the second step of the process, the field becomes [2,0,2][2, 0, 2]. Then place the figure in the second column and after the second step of the process, the field becomes [0,0,0][0, 0, 0].

And the second test case of the example field is shown below:

It can be shown that you cannot do anything to end the process.

In the third test case of the example, you first place the figure in the second column after the second step of the process, the field becomes [0,2][0, 2]. Then place the figure in the first column and after the second step of the process, the field becomes [0,0][0, 0].

In the fourth test case of the example, place the figure in the first column, then the field becomes [102][102] after the first step of the process, and then the field becomes [0][0] after the second step of the process.

Samples

4
3
1 1 3
4
1 1 2 1
2
11 11
1
100
YES
NO
YES
YES

在线编程 IDE

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