#include<bits/stdc++.h>
using namespace std;
long long n,k,a[1000000],misuf[1000000],mxpre[1000000];
int main()
{  scanf("%lld",&n);
   for (int i=1;i<=n;i++)  scanf("%lld",&a[i]);
   k=0; mxpre[1]=a[1]; misuf[n]=a[n];
   for (int i=2;i<=n;i++)  mxpre[i]=max(mxpre[i-1],a[i]);
   for (int i=n-1;i>=1;i--)  misuf[i]=min(misuf[i+1],a[i]);
   for (int i=2;i<n;i++)
   if (a[i]!=i && mxpre[i-1]>a[i] && misuf[i+1]<a[i]) k=1;
   for (int i=1;i<n;i++)
   {  if (a[i]!=i && a[i+1]!=i+1 && mxpre[i]!=i) k=1;
      if (a[i]==i && a[i+1]==i+1 && mxpre[i]!=i) k=1;
   }
   if (k==1)  cout<<"No"<<endl; else cout<<"Yes"<<endl;
}