#AGC052D. [AGC052D] Equal LIS

[AGC052D] Equal LIS

Score : 10001000 points

Problem Statement

You are given a permutation P1,P2,,PNP_1, P_2, \dots, P_N of integers from 11 to NN. Is it possible to split it into 22 subsequences, which have equal length of the Longest Increasing Subsequence?

Formally speaking, your goal is to get two integer sequences aa and bb such that:

  • Both aa and bb are subsequences of PP.
  • Each integer i=1,2,,Ni=1,2,\cdots,N appears in exactly one of aa and bb.
  • (The length of a longest increasing subsequence of aa) == (The length of a longest increasing subsequence of bb)

Determine if the objective is achievable.

You will be given TT test cases. Solve each of them.

Constraints

  • 1T21051 \le T \le 2 \cdot 10^5
  • 1N21051 \le N \le 2 \cdot 10^5
  • P1,P2,,PNP_1, P_2, \dots, P_N is a permutation of integers from 11 to NN.
  • The sum of NN over all test cases doesn't exceed 21052 \cdot 10^5.

Input

Input is given from Standard Input in the following format. The first line of input is as follows:

TT

Then, TT test cases follow, each of which is in the following format:

NN

P1P_1 P2P_2 \dots PNP_N

Output

For each test case, print YES if it is possible to split the permutation into 22 subsequences, which have equal length of the Longest Increasing Subsequence, and print NO otherwise. Use one line for each case. Note that the checker is case-insensitive: you can print letters in both uppercase and lowercase.

5
1
1
2
2 1
3
1 2 3
5
1 3 5 2 4
6
2 3 4 5 6 1
NO
YES
NO
YES
NO

[1,3,5,2,4][1, 3, 5, 2, 4] can be split into [1,5][1, 5] and [3,2,4][3, 2, 4], both have LISLIS of length 2.

It can be shown that there is no way to split [2,3,4,5,6,1][2, 3, 4, 5, 6, 1] into 22 subsequences with an equal length of LISLIS.