Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 32768/32768 K (Java/Others)

In computer science, the longest increasing subsequence problem is to find a subsequence of a given sequence in which the subsequence's elements are in sorted order, lowest to highest, and in which the subsequence is as long as possible. This subsequence is not necessarily contiguous, or unique.

---Wikipedia

Today, LIS takes revenge on you, again. You mission is not calculating the length of longest increasing subsequence, but the length of the second longest increasing subsequence.

Two subsequence is different if and only they have different length, or have at least one different element index in the same place. And second longest increasing subsequence of sequence S indicates the second largest one while sorting all the increasing subsequences of S by its length.

---Wikipedia

Today, LIS takes revenge on you, again. You mission is not calculating the length of longest increasing subsequence, but the length of the second longest increasing subsequence.

Two subsequence is different if and only they have different length, or have at least one different element index in the same place. And second longest increasing subsequence of sequence S indicates the second largest one while sorting all the increasing subsequences of S by its length.

The first line contains a single integer T, indicating the number of test cases.

Each test case begins with an integer N, indicating the length of the sequence. Then N integer Ai follows, indicating the sequence.

[Technical Specification]

1. 1 <= T <= 100

2. 2 <= N <= 1000

3. 1 <= Ai <= 1 000 000 000

Each test case begins with an integer N, indicating the length of the sequence. Then N integer Ai follows, indicating the sequence.

[Technical Specification]

1. 1 <= T <= 100

2. 2 <= N <= 1000

3. 1 <= Ai <= 1 000 000 000

提交代码