Codeforces Global Round 17
B
Kalindrome Array
Codeforces
1100
原题
← AC →
翻译中…

An array $[b_1, b_2, \ldots, b_m]$ is a palindrome, if $b_i = b_{m+1-i}$ for each $i$ from $1$ to $m$. Empty array is also a palindrome.

翻译中…

An array is called kalindrome, if the following condition holds:

翻译中…
  • It's possible to select some integer $x$ and delete some of the elements of the array equal to $x$, so that the remaining array (after gluing together the remaining parts) is a palindrome.
翻译中…

Note that you don't have to delete all elements equal to $x$, and you don't have to delete at least one element equal to $x$.

翻译中…

For example :

翻译中…
  • $[1, 2, 1]$ is kalindrome because you can simply not delete a single element.
  • $[3, 1, 2, 3, 1]$ is kalindrome because you can choose $x = 3$ and delete both elements equal to $3$, obtaining array $[1, 2, 1]$, which is a palindrome.
  • $[1, 2, 3]$ is not kalindrome.
翻译中…

You are given an array $[a_1, a_2, \ldots, a_n]$. Determine if $a$ is kalindrome or not.

翻译中…

Input

翻译中…

The first line contains a single 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 length of the array.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) — elements of the array.

翻译中…

It's guaranteed that the sum of $n$ over all test cases won't exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, print YES if $a$ is kalindrome and NO otherwise. You can print each letter in any case.

翻译中…

Note

翻译中…

In the first test case, array $[1]$ is already a palindrome, so it's a kalindrome as well.

翻译中…

In the second test case, we can choose $x = 2$, delete the second element, and obtain array $[1]$, which is a palindrome.

翻译中…

In the third test case, it's impossible to obtain a palindrome.

翻译中…

In the fourth test case, you can choose $x = 4$ and delete the fifth element, obtaining $[1, 4, 4, 1]$. You also can choose $x = 1$, delete the first and the fourth elements, and obtain $[4, 4, 4]$.

翻译中…

样例

Input #1
4
1
1
2
1 2
3
1 2 3
5
1 4 4 1 4
Output #1
YES
YES
NO
YES
InputCopy OutputCopy
题目信息
题号
1610B
时间限制
1 s
内存限制
256 MB
标签
贪心
双指针

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