#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, seila;
	stack<int> a, est, b;
	while (cin >> n && n) {
		while (cin >> seila) {
			if (!seila) {
				cout << "\n";
				break;
			}
			while (!a.empty()) a.pop();
			while (!est.empty()) est.pop();
			while (!b.empty()) b.pop();
			a.push(seila);
			b.push(1);
			for (int i=2; i<=n; ++i) {
				cin >> seila;
				a.push(seila);
				b.push(i);
			}
			while (!a.empty() || !est.empty() || !b.empty()) {
				if (!a.empty() && !b.empty() && a.top() == b.top()) {
					a.pop();
					b.pop();
				} else if (!est.empty() && !b.empty() && est.top() == b.top()) {
					est.pop();
					b.pop();
				} else if (!a.empty()) {
					est.push(a.top());
					a.pop();
				} else {
					break;
				}
			}
			if (a.empty() && est.empty() && b.empty())
				cout << "Yes\n";
			else
				cout << "No\n";
		}
	}
}