    #include<bits/stdc++.h>
    using namespace std;
    const int N=3e5+5;
    int n,a[N],b[N];
    void work(){
    	puts("No");
    	exit(0);
    }
    void check(int l,int r){
    	for(int i=l,ml=0,mr=0;i<=r;i++)
    		if(a[i]<i){
    			if(ml>a[i]||a[i]>r||a[i]<l)	work();
    			ml=max(ml,a[i]);
    		}
    		else	if(a[i]>i){
    			if(mr>a[i]||a[i]>r||a[i]<l)	work();
    			mr=max(mr,a[i]);
    		}
    }
    int main(){
    	scanf("%d",&n);
    	for(int i=1;i<=n;i++)	scanf("%d",&a[i]),b[i]=a[i]==i;
    	for(int i=2;i<n;i++)	if(!b[i-1]&&!b[i]&&!b[i+1])	work();
    	for(int l=1;l<=n;l++)
    		if(!b[l]){
    			int r=l,now=1;
    			while(r<=n&&b[r]^now)	++r,now^=1;
    			check(l,--r),l=r;
    		}
    	puts("Yes");
    	return 0;
    }