CF2191B.MEX Reordering

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

MEX Reordering

You are given an integer array aa consisting of nn elements. Denote $f(l, r) = \operatorname{MEX}([a_l, a_{l + 1}, \ldots, a_r])$^{\text{∗}}.

Determine if there is a way to reorder the array aa such that for every ii (1in11 \le i \le n - 1), f(1,i)f(i+1,n)f(1, i) \neq f(i + 1, n). In other words, for every split point ii, the MEX\operatorname{MEX} of the prefix must be different from the MEX\operatorname{MEX} of the suffix.

^{\text{∗}}The minimum excluded (MEX) of a collection of integers c1,c2,,ckc_1, c_2, \ldots, c_k is defined as the smallest non-negative integer xx which does not occur in the collection cc.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t5001 \le t \le 500). The description of the test cases follows.

The first line of each test case contains a single integer nn (2n1002 \le n \le 100) — the length of the array.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ain0 \le a_i \le n).

Output

Output "YES" if you can reorder aa so that the condition from the statement is satisfied, and "NO" otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Note

In the first example, the initial ordering of aa already satisfies the condition. The only choice for ii is i=1i = 1. Then $f(1, i) = f(1, 1) = \operatorname{MEX}([a_1]) = \operatorname{MEX}([1]) = 0$, and $f(i + 1, n) = f(2, 2) = \operatorname{MEX}([a_2]) = \operatorname{MEX}([0]) = 1$. Since 010 \neq 1, the condition is satisfied.

In the second example, it can be shown that there is no way to reorder aa to satisfy the condition. As an example, consider the order a=[3,0,0]a = [3, 0, 0] and i=2i = 2. We have $f(1, i) = f(1, 2) = \operatorname{MEX}([a_1, a_2]) = \operatorname{MEX}([3, 0]) = 1$, and $f(i + 1, n) = f(3, 3) = \operatorname{MEX}([a_3]) = \operatorname{MEX}([0]) = 1$, hence f(1,i)=f(i+1,n)f(1, i) = f(i + 1, n), so the choice of reordering is invalid.

In the third example, we can reorder aa into [1,6,1,0,0,5][1, 6, 1, 0, 0, 5]. When i=4i = 4, $f(1, i) = f(1, 4) = \operatorname{MEX}([a_1, a_2, a_3, a_4]) = \operatorname{MEX}([1, 6, 1, 0]) = 2$, $f(i + 1, n) = f(5, 6) = \operatorname{MEX}([a_5, a_6]) = \operatorname{MEX}([0, 5]) = 1$, so the condition is satisfied for this ii. It can be verified that the condition is also satisfied for all other ii.

Samples

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

在线编程 IDE

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