CF2163A.Souvlaki VS. Kalamaki

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

Souvlaki VS. Kalamaki

Two players, Souvlaki and Kalamaki, are given a sequence aa of nn integers.

They will play a game that consists of n1n-1 rounds, which are numbered from 11 to n1n-1. Souvlaki plays on odd-numbered rounds, and Kalamaki on even-numbered rounds.

On the ii-th round, a player can choose to take exactly one of the following actions:

  • Skip his turn and proceed to round i+1i+1 (or finish the game if round ii was the last one).
  • Swap elements aia_i and ai+1a_{i+1}.

Souvlaki wins if after the end of the last round, aa is sorted in non-decreasing order. In other words, he wins if aiai+1a_i \le a_{i+1} holds for every 1i<n1 \le i \lt n. Otherwise, Kalamaki wins.

However, Souvlaki does not like losing, so before the start of the game, he may re-order the elements of aa in anyway he wants. Is it possible for him to do so such that he has a guaranteed winning strategy?

Input

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

The first line of each test case contains a single integer, nn (3n1003 \le n \le 100) — the number of integers in aa.

The second line contains exactly nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ain1 \le a_i \le n) — where aia_i represents the ii-th element of aa.

Output

For each test case, output on a separate line "'YES"' if it is possible for Souvlaki to re-order the elements of aa such that he has a guaranteed winning strategy, 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, a=[4,2,2,1]a = [4, 2, 2, 1]. A possible way to re-order the elements so that Souvlaki can win is the following: a=[2,1,2,4]a = [2, 1, 2, 4]. Then, the game might go as follows:

  1. On round 11, it is Souvlaki's turn. He will choose to swap a1a_1 with a2a_2, and now a=[1,2,2,4]a = [1, 2, 2, 4].
  2. On round 22, it is Kalamaki's turn. Whether he chooses to skip his turn or swap elements a2a_2 and a3a_3, aa will remain the same. Suppose he skips his turn.
  3. On round 33, it is Souvlaki's turn. He can choose to skip his turn as well, because if he swapped the last two elements he would lose.

After every round, a=[1,2,2,4]a = [1, 2, 2, 4], sorted in non-decreasing order, so Souvlaki wins, no matter how Kalamaki chooses to play.

On the second example, since every element is equal, Souvlaki will always win because aa is always sorted in non-decreasing order.

Samples

5
4
4 2 2 1
4
1 1 1 1
5
1 5 1 5 1
3
1 2 3
5
1 3 2 3 5
YES
YES
YES
NO
NO

在线编程 IDE

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