#include <bits/stdc++.h>
using namespace std;
const int maxn=300005;
int a[maxn];
int chk(int l,int r){
  static int q[maxn];
  //printf("chk %d %d\n",l,r);
  int mx=1,mn=maxn;
  for(int i=l;i<=r;i++){
    mx=max(mx,a[i]);
    mn=min(mn,a[i]);
  }
  if(mx!=r||mn!=l)return 0;
  int top=0;
  for(int i=l;i<=r;i+=2){
    int x=top;
    for(;x&&a[i]>a[q[x]];x--);
    if(x==top)top++;
    if(top==3)return 0;
    q[++x]=i;
  }
  return 1;
}
int main(){
  //freopen("aa.in","r",stdin);
  int n;scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%d",a+i);
  }
  for(int i=1;i<=n;i++)if(a[i]!=i){
    int j=i+2;
    for(;j<=n&&a[j]!=j&&a[j-1]==j-1;j+=2);j-=2;
    if(!chk(i,j))return puts("No"),0;
    i=j;
  }
  puts("Yes");
  return 0;
}