#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <utility>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define IN() freopen("in.txt", "r", stdin)
#define OUT() freopen("out.txt", "w", stdout)
const int maxn = 1000005;
using LL = long long;
using UI = unsigned int;
const int mod = 1e6 + 7;
using namespace std;
//------------------------------------------------------------------------------------------//
int q[1005] = { 0 }, rear = 0, front = 0;
int s[1005] = { 0 }, sfront = 0;
bool judge(int x) {
if (x >= q[rear] && front != rear) {//若出栈的数大于等于队首的数,则应当把数入栈,当然队列空了也要考虑
while (q[rear] != x) s[sfront++] = q[rear++];//把到x为止的所有数入栈,出队
rear++;//x出队,入栈出栈
}
else {
if (s[--sfront] != x) return false;//比较栈顶元素与出栈元素
}
return true;
}
int main() {
#ifdef _DEBUG
IN(); OUT();
#endif
int N;
while (cin >> N && N) {
int x;
while (cin >> x && x) {
bool flag = true;
CLEAR(q, 0), rear = 0, front = 0;
CLEAR(s, 0), sfront = 0;
for (int i = 1; i <= N; i++) q[front++] = i;//入队
if (!judge(x)) flag = false;
for (int i = 0; i < N - 1; ++i) {
scanf("%d", &x);
if (!judge(x)) flag = false;
}
if (flag) cout << "Yes\n";
else cout << "No\n";
}
cout << endl;
}
return 0;
}
//参考了lls的代码
int a[1005];
int main() {
#ifdef _DEBUG
IN(); OUT();
#endif
int n;
while (cin >> n && n) {
while (cin >> a[1] && a[1]) {
stack<int> s;
bool flag = true;
for (int i = 2; i <= n; ++i) cin >> a[i];
int A = 1, B = 1;//定义A,B两个类似指针的变量来比较,值得学习。
while (B != n) {//这个循环把情况全考虑了,,,好厉害啊。。
if (A == a[B]) A++, B++;
else if (!s.empty() && s.top() == a[B]) s.pop(), B++;
else if (A < a[B]) s.push(A++);
else { flag = false; break; }
}
if (flag) cout << "Yes" << endl;
else cout << "No" << endl;
}
cout << endl;
}
return 0;
}