建树
输出,并检查
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2220000 + 7;
int n, m, f;
int a[maxn], b[maxn];
void build1() {
memset(a, -1, sizeof a);
for(int i = 0; i < n; ++i) {
int id = 1, x;
scanf("%d", &x);
while(1) {
if(a[id] == -1) {
a[id] = x; break;
}
else if(x > a[id]) {
id *= 2;
}
else id = 2*id+1;
}
}
}
bool check() {
f = 1;
int cnt = 0;
for(int i = 1; i < maxn; ++i) {
if(a[i] != -1) {
cnt++;
cout << a[i];
cout << (cnt == n ? "\n" : " ");
}
else {
f = 0;
}
if(cnt == n) break;
}
if(!f) return false;
return true;
}
int main() {
while(~scanf("%d", &n) && n) {
build1();
if(check()) puts("YES");
else puts("NO");
}
return 0;
}