atcoder#ARC102D. [ARC102F] Revenge of BBuBBBlesort!

[ARC102F] Revenge of BBuBBBlesort!

Score : 12001200 points

Problem Statement

You are given a permutation of 1,2,...,N1,2,...,N: p1,p2,...,pNp_1,p_2,...,p_N. Determine if the state where pi=ip_i=i for every ii can be reached by performing the following operation any number of times:

  • Choose three elements pi1,pi,pi+1p_{i-1},p_{i},p_{i+1} (2iN12\leq i\leq N-1) such that pi1>pi>pi+1p_{i-1}>p_{i}>p_{i+1} and reverse the order of these three.

Constraints

  • 3N3×1053 \leq N \leq 3 \times 10^5
  • p1,p2,...,pNp_1,p_2,...,p_N is a permutation of 1,2,...,N1,2,...,N.

Input

Input is given from Standard Input in the following format:

NN

p1p_1

::

pNp_N

Output

If the state where pi=ip_i=i for every ii can be reached by performing the operation, print Yes; otherwise, print No.

5
5
2
1
4
3
Yes

The state where pi=ip_i=i for every ii can be reached as follows:

  • Reverse the order of p1,p2,p3p_1,p_2,p_3. The sequence pp becomes 1,2,5,4,31,2,5,4,3.
  • Reverse the order of p3,p4,p5p_3,p_4,p_5. The sequence pp becomes 1,2,3,4,51,2,3,4,5.
4
3
2
4
1
No
7
3
2
1
6
5
4
7
Yes
6
5
3
4
1
2
6
No