Pinely Round 1 (Div. 1 + Div. 2)
B
Elimination of a Ring
Codeforces
1000
原题
← AC →
翻译中…

Define a cyclic sequence of size $n$ as an array $s$ of length $n$, in which $s_n$ is adjacent to $s_1$.

翻译中…

Muxii has a ring represented by a cyclic sequence $a$ of size $n$.

翻译中…

However, the ring itself hates equal adjacent elements. So if two adjacent elements in the sequence are equal at any time, one of them will be erased immediately. The sequence doesn't contain equal adjacent elements initially.

翻译中…

Muxii can perform the following operation until the sequence becomes empty:

翻译中…
  • Choose an element in $a$ and erase it.
翻译中…

For example, if ring is $[1, 2, 4, 2, 3, 2]$, and Muxii erases element $4$, then ring would erase one of the elements equal to $2$, and the ring will become $[1, 2, 3, 2]$.

翻译中…

Muxii wants to find the maximum number of operations he could perform.

翻译中…

Note that in a ring of size $1$, its only element isn't considered adjacent to itself (so it's not immediately erased).

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains a single integer $t$ ($1\leq t\leq 100$) — the number of test cases. The description of test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1\leq n\leq 100$) — the size of the cyclic sequence.

翻译中…

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

翻译中…

It's guaranteed that $a_i\ne a_{i+1}$ for $1\leq i \lt n$.

翻译中…

It's guaranteed that $a_n\ne a_1$ when $n \gt 1$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the maximum number of operations Muxii can perform.

翻译中…

Note

翻译中…

In the first test case, you can erase the second element first, then erase the remaining elements one by one in any order. In total, you can perform the operation $4$ times. Note that if you erase the first element first, then the sequence will be turned into $[2,3,2]$ and then immediately become $[2,3]$.

翻译中…

In the second test case, you can erase the first element first, then the sequence becomes $[2,1]$. Then you can erase all remaining elements one by one in any order.

翻译中…

样例

Input #1
3
4
1 2 3 2
4
1 2 1 2
1
1
Output #1
4
3
1
InputCopy OutputCopy
题目信息
题号
1761B
时间限制
1 s
内存限制
256 MB
标签
构造
贪心
模拟

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