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 Rust (1.15.1) (judge verdict: Wrong Answer)

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn calc(n: usize, a: &[usize]) -> Option<Vec<usize>> {
    let mut a: Vec<Option<usize>> =
        a.into_iter().map(|x| x.checked_sub(1)).collect();
    let mut unused = vec![true; 1 << n];
    for &a in a.iter() {
        if let Some(a) = a {
            unused[a] = false;
        }
    }
    let mut unused: BTreeSet<usize> = (0 .. 1 << n).filter(|&i| unused[i]).collect();
    for bits in 0 .. 1 << n {
        if a[bits].is_some() { continue; }
        let mut lo = 0;
        for i in 0 .. n {
            if (bits & 1 << i) == 0 { continue; }
            lo = max(lo, a[bits ^ 1 << i].unwrap() + 1);
        }
        // Find the minimum value in unused that is >= lo
        let elem;
        let mut spl = unused.split_off(&lo);
        {
            let k = spl.iter().next();
            // eprintln!("k = {:?}", k);
            elem = match k {
                None => return None,
                Some(&x) => x,
            };
        }
        spl.remove(&elem);
        a[bits] = Some(elem);
        // TODO TLE
        unused.append(&mut spl);
    }
    let mut a: Vec<usize> = a.into_iter().map(|x| x.unwrap()).collect();
    let olda = a.clone();
    // eprintln!("olda = {:?}", olda);
    'whole:
    for b in 0 .. n {
        for i in 0 .. 1 << (n - b - 1) {
            // TODO Merging is better, it's O(n log n), unnecessarily slow
            a[i << (b + 1) .. (2 * i + 1) << b].sort();
            a[(2 * i + 1) << b .. (i + 1) << (b + 1)].sort();
            for j in 0 .. 1 << b {
                if a[(i << (b + 1)) + j] > a[((2 * i + 1) << b) + j] {
                    return None;
                }
            }
        }
    }
    // rearrange
    let mut ans = vec![0; 1 << n];
    let mut j = 0;
    ans[0] = olda[0];
    for i in 1 .. 1 << n {
        let mut k = 1 << (n - 1);
        loop {
            j ^= k;
            if j >= k { break; }
            k >>= 1;
        }
        ans[j] = olda[i];
    }
    Some(ans)
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        a: [usize; 1 << n],
    }
    let ans = calc(n, &a);
    if let Some(ans) = ans {
        puts!("YES\n");
        // rearrange
        for i in 0 .. 1 << n {
            puts!("{}{}", ans[i] + 1, if i == (1 << n) - 1 { "\n" } else { " " });
        }
    } else {
        puts!("NO\n");
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}