#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <iostream>
typedef long long ll;
using namespace std;
const int maxn=300100;
int ai[maxn];
int n;

bool check(int l,int r){
    int minx=n+10,maxx=0;
    for(int i=l;i<=r;i++){
        minx=min(minx,ai[i]);
        maxx=max(maxx,ai[i]);
    }
    if(minx<l||maxx>r) return true;
    int x1=0,x2=0;
    for(int i=l;i<=r;i++){
        if(ai[i]!=i){
            if(ai[i]>i){
                if(x1<ai[i]) x1=ai[i];
                else return true;
            }else{
                if(x2<ai[i]) x2=ai[i];
                else return true;
            }
        }
    }
    return false;
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&ai[i]);
    for(int i=1;i<=n;i++){
        if(ai[i]!=i){
            int x;
            for(x=i;ai[x+1]==x+1&&ai[x+2]!=x+2;){
                x+=2;
            }
            x=min(x,n);
            //cout<<i<<"   "<<x<<endl;
            if(check(i,x)) return puts("No"),0;
            i=x;
        }
    }
    puts("Yes");
    return 0;
}