http://hz.wkjsj.org/oj/problem.php?id=1011
#include <iostream>
#include <cstdlib>
#include <stack>
#include <queue>
using namespace std;
bool solve(queue<int> & q)
{
stack<int> s;
int n = q.size();
int i;
for (i = 1; i <= n; i++)
{
s.push(i);
while (!q.empty() && !s.empty() && q.front() == s.top())
{
q.pop();
s.pop();
}
}
return q.empty();
}
int main()
{
int n, tmp, i;
bool first = true;
queue<int> q;
while (cin >> n, n)
{
if (!first)
{
cout << endl;
}
else
{
first = false;
}
while (cin >> tmp, tmp)
{
while (!q.empty())
q.pop();
q.push(tmp);
for (i = 0; i < n - 1; i++)
{
cin >> tmp;
q.push(tmp);
}
cout << (solve(q) ? "Yes" : "No") << endl;
}
}
return 0;
}