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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeSet;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        FullTournament solver = new FullTournament();
        solver.solve(1, in, out);
        out.close();
    }

    static class FullTournament {
        public int[] arr;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            arr = in.readIntArray(1 << n);
            ArrayList<Integer> avail = new ArrayList<>();
            for (int i = 1; i <= 1 << n; i++) avail.add(i);
            ArrayList<Integer> res = solve(avail, 0, (1 << n) - 1);
            if (res == null) {
                out.println("NO");
            } else {
                out.println("YES");
                boolean first = true;
                for (int k : res) {
                    if (!first) out.print(" ");
                    out.print(k);
                    first = false;
                }
                out.println();
            }
        }

        public ArrayList<Integer> solve(ArrayList<Integer> avail, int from, int to) {
            if (from == to) {
                if (arr[from] != 0 && avail.get(0) != arr[from]) {
                    return null;
                } else {
                    return new ArrayList<>(avail);
                }
            }
            int mid = (from + to) / 2;
            TreeSet<Integer> lh = new TreeSet<>(), rh = new TreeSet<>();
            for (int i = from; i <= mid; i++) if (arr[i] != 0) lh.add(arr[i]);
            for (int i = mid + 1; i <= to; i++) if (arr[i] != 0) rh.add(arr[i]);

            int lpos = from, rpos = mid + 1;
            ArrayList<Integer> al = new ArrayList<>(), ar = new ArrayList<>();
            for (int k : avail) {
                if (lpos == mid + 1) {
                    ar.add(k);
                    rpos++;
                    continue;
                }
                if (rpos == to + 1) {
                    al.add(k);
                    lpos++;
                    continue;
                }

                if (rh.size() > 0 && rh.first() == k) {
                    rh.pollFirst();
                    ar.add(k);
                    rpos++;
                    continue;
                }
                if (lh.size() > 0 && lh.first() == k) {
                    lh.pollFirst();
                    al.add(k);
                    lpos++;
                    continue;
                }
                if (al.size() == ar.size()) {
                    al.add(k);
                    lpos++;
                    continue;
                }
                ar.add(k);
                rpos++;
            }

            ArrayList<Integer> r1 = solve(al, from, mid), r2 = solve(ar, mid + 1, to);
            if (r1 == null || r2 == null) return null;
            ArrayList<Integer> ret = new ArrayList<>();
            for (int i = 0; i < r1.size(); i++) {
                int a = r1.get(i), b = r2.get(i);
                ret.add(a);
                ret.add(b);
            }
            return ret;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println() {
            writer.println();
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void print(int i) {
            writer.print(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1 << 16];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int[] readIntArray(int tokens) {
            int[] ret = new int[tokens];
            for (int i = 0; i < tokens; i++) {
                ret[i] = nextInt();
            }
            return ret;
        }

        public int read() {
            if (this.numChars == -1) {
                throw new InputMismatchException();
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0;

                    try {
                        this.numChars = this.stream.read(this.buf);
                    } catch (IOException var2) {
                        throw new InputMismatchException();
                    }

                    if (this.numChars <= 0) {
                        return -1;
                    }
                }

                return this.buf[this.curChar++];
            }
        }

        public int nextInt() {
            int c;
            for (c = this.read(); isSpaceChar(c); c = this.read()) {
                ;
            }

            byte sgn = 1;
            if (c == 45) {
                sgn = -1;
                c = this.read();
            }

            int res = 0;

            while (c >= 48 && c <= 57) {
                res *= 10;
                res += c - 48;
                c = this.read();
                if (isSpaceChar(c)) {
                    return res * sgn;
                }
            }

            throw new InputMismatchException();
        }

        public static boolean isSpaceChar(int c) {
            return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
        }

    }
}