/*#include <iostream>
#include <stack>
using namespace std;
int main(){
int n,a[1050]={},b[1050]={};
cin>>n;
for(int i=1;i<=n;i++) a[i]=i;
//for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>b[i];
stack<int> c;
int j=1;//a的当前车头
for(int i=1;i<=n;i++){
int x=b[i];//以x为目标,查看c中是否有x车
if(c.empty()) c.push(a[j++]);
if(c.top()==x) c.pop();
else{
while(j<=n&&a[j]!=x) c.push(a[j++]);
if(a[j]==x) j++;
else { cout<<"NO";return 0; }
}
}
cout<<"YES";
return 0;
}*/
#include <iostream>
using namespace std;
int main()
{
int n, a[1050] = {}, b[1050] = {};
cin >> n;
for (int i = 1; i <= n; i++)
a[i] = i;
// for(int i=1;i<=n;i++) cin>>a[i];
for (int i = 1; i <= n; i++)
cin >> b[i];
int c[1050] = {}, t = 0;
int j = 1; // a的当前车头
for (int i = 1; i <= n; i++)
{
int x = b[i]; // 以x为目标,查看c中是否有x车
if (t == 0)
c[t++] = a[j++];
if (c[t - 1] == x)
t--;
else
{
while (j <= n && a[j] != x)
c[t++] = a[j++];
if (a[j] == x)
j++;
else
{
cout << "NO";
return 0;
}
}
}
cout << "YES";
return 0;
}