Problem:
Score : 1600 points

Problem Statement

2^N players competed in a tournament.
Each player has a unique ID number from 1 through 2^N. When two players play a match, the player with the smaller ID always wins.

This tournament was a little special, in which losers are not eliminated to fully rank all the players.

We will call such a tournament that involves 2^n players a full tournament of level n.
In a full tournament of level n, the players are ranked as follows:

In a full tournament of level 0, the only player is ranked first.

In a full tournament of level n\ (1 \leq n), initially all 2^n players are lined up in a row. Then:

First, starting from the two leftmost players, the players are successively divided into 2^{n-1} pairs of two players.

Each of the pairs plays a match. The winner enters the "Won" group, and the loser enters the "Lost" group.

The players in the "Won" group are lined up in a row, maintaining the relative order in the previous row. Then, a full tournament of level n-1 is held to fully rank these players.

The players in the "Lost" group are also ranked in the same manner, then the rank of each of these players increases by 2^{n-1}.

For example, the figure below shows how a full tournament of level 3 progresses when eight players are lined up in the order 3,4,8,6,2,1,7,5. The list of the players sorted by the final ranking will be 1,3,5,6,2,4,7,8.

Takahashi has a sheet of paper with the list of the players sorted by the final ranking in the tournament, but some of it blurred and became unreadable.
You are given the information on the sheet as a sequence A of length N. When A_i is 1 or greater, it means that the i-th ranked player had the ID A_i. If A_i is 0, it means that the ID of the i-th ranked player is lost.

Determine whether there exists a valid order in the first phase of the tournament which is consistent with the sheet. If it exists, provide one such order.

Constraints

1 \leq N \leq 18

0 \leq A_i \leq 2^N

No integer, except 0, occurs more than once in A_i.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_{2^N}

Output

If there exists a valid order in the first phase of the tournament, print YES first, then in the subsequent line, print the IDs of the players sorted by the final ranking, with spaces in between.
If there is no such order, print NO instead.

Sample Input 1

3
0 3 0 6 0 0 0 8

Sample Output 1

YES
3 4 8 6 2 1 7 5

This is the same order as the one in the statement.

Sample Input 2

1
2 1

Sample Output 2

NO

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define befv(V) ((V)[(sz(V)-2)])
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
void fuk() { puts("NO"); exit(0); }

const bool debug = 0;
const int MAXM = 262144 + 55;

priority_queue<pii, vector<pii>, greater<pii>> PQ;
vector<int> G[MAXM], T[MAXM];
int C[MAXM], D[MAXM], E[MAXM];

int A[MAXM], B[MAXM], O[MAXM];

int N, M;

int main() {
	ios::sync_with_stdio(false);

	cin >> N; M = 1<<N;
	for(int i = 1; i <= M; i++) cin >> A[i];
	for(int i = 1; i <= M; i++)
		for(int j = 0; j < 19; j++)
			if(i & (1<<j)) B[i]++;
	iota(O, O+M, 0); sort(O, O+M, [&](int a, int b) { return B[a] > B[b]; });

	for(int i = 0; i < M; i++) {
		for(int j = 0; j < N; j++)
			if(!(i & (1<<j)))
				G[i | 1<<j].eb(i);
		C[i] = (1 << B[i]) - 1;
		D[i] = M - (1 << (N-B[i]));
	}

	for(int oi = 0, i; oi < M; oi++) {
		i = O[oi];
		if(A[i+1]) {
			int t = A[i+1]-1;
			if(t < C[i] || D[i] < t) fuk();
			C[i] = D[i] = t;
		}
		for(int v : G[i]) upmin(D[v], D[i]-1);
		T[C[i]].eb(i);
	}

	if(debug) {
		printf("N=%d, M=%d\n", N, M);
		for(int i = 0; i < M; i++)
			printf("%d ; %d %d\n", i, C[i], D[i]);
	}

	for(int day = 0; day < M; day++) {
		auto &V = T[day];
		for(int v : V) PQ.push(pii(D[v], v));
		if(PQ.empty()) fuk();
		int idx = PQ.top().second; PQ.pop();
		if(D[idx] < day) fuk();
		E[idx] = day+1;
	}

	puts("YES");
	for(int i = 0; i < M; i++) {
		int idx = 0, j = i;
		for(int k = 0; k < N; k++) {
			idx = idx << 1 | (j & 1);
			j >>= 1;
		}
		printf("%d ", E[idx]);
	}
	puts("");
	return 0;
}