Problem:
Score : 1200 points

Problem Statement

You are given a permutation of 1,2,...,N: p_1,p_2,...,p_N. Determine if the state where p_i=i for every i can be reached by performing the following operation any number of times:

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

Constraints

3 \leq N \leq 3 × 10^5

p_1,p_2,...,p_N is a permutation of 1,2,...,N.

Input

Input is given from Standard Input in the following format:

N
p_1
:
p_N

Output

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

Sample Input 1

5
5
2
1
4
3

Sample Output 1

Yes

The state where p_i=i for every i can be reached as follows:

Reverse the order of p_1,p_2,p_3. The sequence p becomes 1,2,5,4,3.

Reverse the order of p_3,p_4,p_5. The sequence p becomes 1,2,3,4,5.

Sample Input 2

4
3
2
4
1

Sample Output 2

No

Sample Input 3

7
3
2
1
6
5
4
7

Sample Output 3

Yes

Sample Input 4

6
5
3
4
1
2
6

Sample Output 4

No

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

/***************************************************************
	File name: F.cpp
	Author: huhao
	Create time: Sun 07 Jun 2020 02:34:32 PM CST
***************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=r*10+c-48;
		c=getchar();
	}
	return r*t;
}
const int N=300010;
int n,p[N];
int check(int l,int r)
{
	fr(i,l,r) if(p[i]<l||p[i]>r) return 0;
	int lst=n;
	for(int i=l;i<=r;i+=2) if(p[i]<=i)
	{
		if(p[i]>lst) return 0;
		lst=i;
	}
	lst=0;
	for(int i=l;i<=r;i+=2) if(p[i]>=i)
	{
		if(p[i]<lst) return 0;
		lst=i;
	}
	return 1;
}
int main()
{
	n=read();
	fr(i,1,n) p[i]=read();
	for(int l=1,r=1;r<=n;l=++r)
	{
		if(p[r]==r) continue;
		while(r+2<=n&&p[r+1]==r+1) r+=2;
		if(!check(l,r)){ printf("No\n"); return 0; }
	}
	printf("Yes\n");
	return 0;
}