CF1851B.Parity Sort

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Parity Sort

You have an array of integers aa of length nn. You can apply the following operation to the given array:

  • Swap two elements aia_i and aja_j such that iji \neq j, aia_i and aja_j are either both even or both odd.

Determine whether it is possible to sort the array in non-decreasing order by performing the operation any number of times (possibly zero).

For example, let aa = [7,10,1,3,27, 10, 1, 3, 2]. Then we can perform 33 operations to sort the array:

  1. Swap a3=1a_3 = 1 and a1=7a_1 = 7, since 11 and 77 are odd. We get aa = [1,10,7,3,21, 10, 7, 3, 2];
  2. Swap a2=10a_2 = 10 and a5=2a_5 = 2, since 1010 and 22 are even. We get aa = [1,2,7,3,101, 2, 7, 3, 10];
  3. Swap a4=3a_4 = 3 and a3=7a_3 = 7, since 33 and 77 are odd. We get aa = [1,2,3,7,101, 2, 3, 7, 10].

Input

The first line of input data contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The description of the test cases follows.

The first line of each test case contains one integer nn (1n21051 \le n \le 2 \cdot 10^5) — the length of array aa.

The second line of each test case contains exactly nn positive integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1091 \le a_i \le 10^9) — the elements of array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output on a separate line:

  • YES if the array can be sorted by applying the operation to it some number of times;
  • NO otherwise.

You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as positive response).

Note

The first test case is explained in the problem statement.

Samples

6
5
7 10 1 3 2
4
11 9 3 5
5
11 3 15 3 2
6
10 7 8 1 2 3
1
10
5
6 6 4 1 6
YES
YES
NO
NO
YES
NO

在线编程 IDE

建议全屏模式获得最佳体验