#733
Silver III
More Cow Photos
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

The cows are in a particularly mischievous mood today! All Farmer John wants to do is take a photograph of the cows standing in a line, but they keep moving right before he has a chance to snap the picture.

Specifically, each of FJ's NN cows (1N105)(1 \le N \le 10^5) has an integer height from 11 to NN. FJ wants to take a picture of the cows standing in line in a very specific ordering. If the cows have heights h1,,hKh_1, \dots, h_K when lined up from left to right, he wants the cow heights to have the following three properties:

He wants the cow heights to increase and then decrease. Formally, there must exist an integer ii such that h1hihKh_1 \le \dots \le h_i \ge \dots \ge h_K.He does not want any cow standing next to another cow with exactly the same height. Formally, hihi+1h_i \neq h_{i+1} for all 1i<K1 \le i < K.He wants the picture to be symmetric. Formally, if i+j=K+1i + j = K+1, then hi=hjh_i = h_j.

FJ wants the picture to contain as many cows as possible. Specifically, FJ can remove some cows and rearrange the remaining ones. Compute the maximum number of cows FJ can have in the picture satisfying his constraints.

입력

You have to answer multiple test cases.

The first line of input contains a single integer TT (1T1051 \leq T \leq 10^5) denoting the number of test cases. TT test cases follow.

The first line of every test case contains a single integer NN. The second line of every test case contains NN integers, the heights of the NN cows available. The cow heights will be between 11 and NN.

It is guaranteed the sum of NN over all test cases will not exceed 10610^6.

출력

Output TT lines, the ii'th line containing the answer to the ii'th test case. Each line should be an integer denoting the maximum number of cows FJ can include in the picture.

예제 입력 1

2
4
1 1 2 3
4
3 3 2 1

예제 출력 1

3
1

점수

Inputs 2-3: T100,N7T\le 100, N \le 7Inputs 4-5: T104T \le 10^4, all cows will have height at most 10.Inputs 6-11: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Silver III1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.