Codeforces Round 1063 (Div. 2)
A
Souvlaki VS. Kalamaki
Codeforces
800
原题
←B →
翻译中…

Two players, Souvlaki and Kalamaki, are given a sequence $a$ of $n$ integers.

翻译中…

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

翻译中…

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

翻译中…
  • Skip his turn and proceed to round $i+1$ (or finish the game if round $i$ was the last one).
  • Swap elements $a_i$ and $a_{i+1}$.
翻译中…

Souvlaki wins if after the end of the last round, $a$ is sorted in non-decreasing order. In other words, he wins if $a_i \le a_{i+1}$ holds for every $1 \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 $a$ 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 $t$ ($1 \le t \le 100$). The description of the test cases follows.

翻译中…

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

翻译中…

The second line contains exactly $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) — where $a_i$ represents the $i$-th element of $a$.

翻译中…

Output

翻译中…

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

翻译中…
  1. On round $1$, it is Souvlaki's turn. He will choose to swap $a_1$ with $a_2$, and now $a = [1, 2, 2, 4]$.
  2. On round $2$, it is Kalamaki's turn. Whether he chooses to skip his turn or swap elements $a_2$ and $a_3$, $a$ will remain the same. Suppose he skips his turn.
  3. On round $3$, 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]$, 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 $a$ is always sorted in non-decreasing order.

翻译中…

样例

Input #1
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
Output #1
YES
YES
YES
NO
NO
InputCopy OutputCopy
题目信息
题号
2163A
时间限制
1 s
内存限制
256 MB
标签
暴力
贪心
数学
排序

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