# Permutation Split SOLUTION PERMSPL

Page Contents

### Permutation Split SOLUTION PERMSPL

For a sequence of positive integers [Math Processing Error], let’s define the number of inversions in it as the number of pairs of integers [Math Processing Error] such that [Math Processing Error] and [Math Processing Error].

You are given a permutation [Math Processing Error] of the integers [Math Processing Error] through [Math Processing Error]. Determine if it is possible to partition this permutation into two subsequences (possibly empty or non-contiguous) such that:

Each element of [Math Processing Error] appears in exactly one of these subsequences.

The numbers of inversions in one subsequence is equal to the number of inversions in the other subsequence.

Input

The first line of the input contains a single integer [Math Processing Error] denoting the number of test cases. The description of [Math Processing Error] test cases follows.

The first line of each test case contains a single integer [Math Processing Error].

The second line contains [Math Processing Error] space-separated integers [Math Processing Error].

Output

For each test case, print a single line containing the string “YES” if it is possible to partition the permutation in a given way or “NO” if it is impossible.

Constraints

[Math Processing Error]

[Math Processing Error] for each valid [Math Processing Error]

[Math Processing Error] are pairwise distinct

the sum of [Math Processing Error] over all test cases does not exceed [Math Processing Error]

Subtask #1 (30 points): [Math Processing Error]

Subtask #2 (70 points): original constraints

Example Input

4

1

1

3

3 2 1

4

4 3 2 1

1 4 3 2 5

Example Output

YES

NO

YES

NO

Explanation

Example case 1: We can split [Math Processing Error] into [Math Processing Error] and [Math Processing Error]. There are [Math Processing Error] inversions in each of these sequences.

Example case 3: We can split [Math Processing Error] into [Math Processing Error] and [Math Processing Error]. There is [Math Processing Error] inversion in each of them. Note that this is not the only solution ― we could also split the permutation into sequences [Math Processing Error] and [Math Processing Error].