#include<bits/stdc++.h>
#define rg register
#define oo 0x7fffffff
#define ll long long
#define GG {puts("No"); return 0;}
using namespace std;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		{
			fh=-1;
			jp=getchar();
		}
	while (jp>='0'&&jp<='9')
		{
			out=out*10+jp-'0';
			jp=getchar();
		}
	return out*fh;
}
const int N=300010;
int n;
int a[N],b[N];
inline bool Check(int l,int r)
{
	int lbd=0,rbd=0;
	for(int i=l; i<=r; i++)
		{
			if(b[i]<i)
				{
					if(lbd>b[i] || (b[i]<l || b[i]>r)) return false;
					lbd=b[i];
				}
			else if(b[i]>i)
				{
					if(rbd>b[i] || (b[i]<l || b[i]>r)) return false;
					rbd=b[i];
				}
		}
	return true;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	for(int i=1; i<=n; i++)
		b[i]=read(),a[i]=(b[i]==i);
	for(int i=2; i<n; i++) if(!a[i-1] && !a[i] && !a[i+1]) GG
			for(int i=1; i<=n; i++)
				{
					if(a[i]==0)
						{
							int now=1;
							int l=i,r=i;
							while((a[r]^now) && r<=n) ++r,now^=1;
							--r;
							if(!Check(l,r)) GG
								i=r;
						}
				}
	puts("Yes");
	return 0;
}
