#include<cstdio> #include<iostream> using namespace std; #include<stack> #include<cstring> int a[10100000]; int main(void) { stack<int> s; int n; while (cin >> n && n) { memset(a, 0, sizeof(a)); for (int i = 1; cin >> a[i] && a[i] != 0; i++); int rec = 1; while (a[rec]) { int ok = 1; int A = 1; int B = rec; while (B <rec+n)//核心代码 { if (A == a[B]) { A++; B++; }//如果相同那么直接进入b else if (!s.empty() && s.top() == a[B]) { s.pop(); B++; }//如果不相同那么和栈顶比较 else if (A <= n)s.push(A++);//以上两个都不可以那么将A插入栈顶 else { ok = 0; break; }//A已经超过了n说明不能进入 } if (ok)cout << "Yes" << endl; else cout << "No" << endl; rec += n; } cout << endl; } return 0; }