代码:
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e3+10;
stack<int>t;
int main(){
int N;
while(1){
scanf("%d",&N);
if(N==0)return 0;
int x=-1,flag=0;
while(1){
while(!t.empty())t.pop();
int now=0;
for(int i=0;i<N;i++){
scanf("%d",&x);
if(x==0)break;
if(x>now){
for(int j=now+1;j<x;j++){
t.push(j);
}
now=x;
}else{
if(t.empty()||t.top()!=x){
cout<<"No"<<endl;
flag=1;
break;
}else{
t.pop();
}
}
}
if(x==0)break;
if(flag==1)continue;
cout<<"Yes"<<endl;
}
cout<<endl;
}
return 0;
}