参见;经典的栈http://www.cppblog.com/sixleaves/archive/2015/03/30/210195.aspx
//@author:yzj Date:2015/07/25
//sourse:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82493#problem/A
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
const int MAXN = 1005;
int a[MAXN], n;
int main()
{
//freopen("F:/yzj/cppCode/input.txt", "r", stdin);
while(scanf("%d", &n) && n)
{
while(scanf("%d", &a[0]) && a[0])
{
for(int i = 1; i < n; i++)
{
scanf("%d", &a[i]);
}
stack<int> s;
int pb=0, pa = 1;bool flag = true;
while(pb < n)
{
if(a[pb]==pa)
{
pa++;pb++;
}
else if(!s.empty() && a[pb]==s.top())
{
s.pop();pb++;
}
else if(a[pb] > pa)
{
s.push(pa);pa++;
}
else
{
flag = false;break;
}
}
if(flag) printf("Yes\n");
else printf("No\n");
}
printf("\n");
}
return 0;
}