| Codeforces Round 1138 (Div. 3) |
|---|
| Finished |
After eating and settling down on a soft blanket by the lake, Sunny and Aubrey began gazing at the sky. The friends noticed an unusual long band of $$$n$$$ clouds, where each cloud is either fluffy and white (represented as "0") or thin and dark (represented as "1"). Let $$$s$$$ be the current string of cloud types.
While watching the sky, Aubrey noticed an unusual phenomenon: when gusts of wind blow through the cloud band, a "cloud swirl" occurs.
In one cloud swirl, the friends can choose two clouds at positions $$$i$$$ and $$$j$$$ ($$$1 \le i \lt j \le |s|$$$) that have the same type ($$$s_i = s_j$$$). As a result of this wind:
Can the friends make the cloud band empty by applying this operation?
Each test consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the initial length of the cloud band.
The second line contains a binary string $$$s$$$ of length $$$n$$$ consisting only of characters '0' and '1'.
The sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print YES if the sky can be completely cleared of clouds, and NO otherwise.
You can output each letter in any case (for example, YES, Yes, yes will be recognized as a positive answer).
7400004010160110102013000410006010001
YESNOYESNONOYESYES
In the third test case, remove the clouds at positions $$$1$$$ and $$$4$$$ in 011010. After the inversion the band reads 0010. Removing positions $$$2$$$ and $$$4$$$ now leaves 00, whose two clouds can disappear together.
In the fourth test case the two clouds have different types, so there is no legal first move.
| Name |
|---|


