#P11013. 「ALFR Round 4」C 粉碎
「ALFR Round 4」C 粉碎
Problem Description
Binbao is playing cards. At first, he has cards, and the value of the -th card is .
Binbao will repeatedly perform the following operation for rounds. The operation in round is:
- Binbao needs to choose to place the -th card on the leftmost side or the rightmost side of the pile.
- If there exist two cards in the pile with the same value, then Binbao will immediately take all cards between these two cards out of the pile and throw them into the shredder (including these two cards themselves).
The insertion operation is always performed before the shattering operation.
The pile is initially empty.
You need to tell Binbao the maximum number of cards he can shatter.
Input Format
The first line contains an integer , indicating the number of test cases.
For each test case:
The first line contains an integer .
The second line contains numbers representing .
Output Format
For each test case, output the maximum number of cards Binbao can shatter.
4
8
1 3 3 1 2 1 2 2
8
3 2 2 1 2 1 2 1
6
1 2 1 2 1 2
6
1 2 3 4 5 6
8
7
6
0
Hint
Sample Explanation
Initial pile:
Put in : ;
Put in : ;
Put in : , then shatter: ;
Put in : ;
Put in : ;
Put in : , then shatter: ;
Put in : ;
Put in : , then shatter: ;
All cards are shattered.
Constraints
| Subtask | Score | Constraints |
|---|---|---|
| and is randomly generated within | ||
| - |
For of the testdata, , , .
Translated by ChatGPT 5