Codeforces Global Round 25
A
Dual Trigger
Codeforces
900
原题
←B →
翻译中…

There are $n$ lamps numbered $1$ to $n$ lined up in a row, initially turned off. You can perform the following operation any number of times (possibly zero):

翻译中…
  • Choose two non-adjacent${}^\dagger$ lamps that are currently turned off, then turn them on.
翻译中…

Determine whether you can reach configuration $s$, where $s_i = 1$ means the $i$-th lamp is turned on, and $s_i = 0$ otherwise.

翻译中…

${}^\dagger$ Only lamp $i$ and $i + 1$ are adjacent for all $1 \le i \lt n$. Note that lamp $n$ and $1$ are not adjacent when $n \ne 2$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains an integer $n$ ($1 \le n \le 50$) — the number of lamps.

翻译中…

The second line of each test case contains a binary string $s$ of size $n$ — the final desired configuration.

翻译中…

Output

翻译中…

For each test case, print on one line "YES" if we can reach the configuration $s$ via applying the given operation any number of times. Otherwise, print "NO".

翻译中…

Note

翻译中…

In the first test case, the sequence of operation could have been as follows (note that initially $s$ is all zero): $\mathtt{0000000000} \to \mathtt{\color{red}{1}0000000\color{red}{1}0} \to \mathtt{1\color{red}{1}00000\color{red}{1}10} \to \mathtt{110\color{red}{1}0\color{red}{1}0110}$.

翻译中…

In the third test case, we don't have to do any operation.

翻译中…

In the fourth test case, we cannot do any operation, but we need the first lamp to be on. Therefore, it is impossible to achieve the desired state.

翻译中…

样例

Input #1
5
10
1101010110
10
1001001110
6
000000
1
1
12
111111111111
Output #1
YES
NO
YES
NO
YES
InputCopy OutputCopy
题目信息
题号
1951A
时间限制
1 s
内存限制
256 MB
标签
构造
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。