Problem:
Score : 800 points

Problem Statement

You are given integers N,\ A and B.
Determine if there exists a permutation (P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the following conditions, and create one such permutation if it exists.

P_0=A

P_{2^N-1}=B

For all 0 \leq i < 2^N-1, the binary representations of P_i and P_{i+1} differ by exactly one bit.

Constraints

1 \leq N \leq 17

0 \leq A \leq 2^N-1

0 \leq B \leq 2^N-1

A \neq B

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

If there is no permutation that satisfies the conditions, print NO.

If there is such a permutation, print YES in the first line.
Then, print (P_0,\ P_1,\ ...\ P_{2^N-1}) in the second line, with spaces in between.
If there are multiple solutions, any of them is accepted.

Sample Input 1

2 1 3

Sample Output 1

YES
1 0 2 3

The binary representation of P=(1,0,2,3) is (01,00,10,11), where any two adjacent elements differ by exactly one bit.

Sample Input 2

3 2 1

Sample Output 2

NO

Solution in Rust (1.15.1) (judge verdict: Runtime Error)

// 0 -> C (< 2^N) をつくる
fn calc(n: usize, c: usize) -> Vec<usize> {
    assert!(c.count_ones() % 2 == 1);
    if n == 1 {
        return vec![0, 1];
    }
    if (c >> (n - 1)) & 1 == 0 {
        let mut i = n - 1;
        while (c >> i) & 1 == 0 {
            i -= 1;
        }
        let mut ans = calc(n, c | (1 << (n - 1)) ^ (1 << i));
        for a in ans.iter_mut() {
            let x = *a >> (n - 1) & 1;
            let y = *a >> i & 1;
            *a &= !(1 << (n - 1)) & !(1 << i);
            *a |= (x << i) | (y << (n - 1));
        }
        return ans;
    }
    let mut f = calc(n - 1, 1);
    let t = calc(n - 1, c ^ (1 << (n - 1)) ^ 1);
    for t in t {
        f.push(t ^ 1 ^ (1 << (n - 1)));
    }
    f
}

fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let a: usize = it.next().unwrap().parse().unwrap();
    let b: usize = it.next().unwrap().parse().unwrap();
    let c = a ^ b;
    if c.count_ones() % 2 == 0 {
        println!("NO");
        return;
    }
    let ans = calc(c, n);
    assert!(ans.windows(2).all(|a| (a[0] ^ a[1]).count_ones() == 1));
    let mut out = String::from("NO\n");
    for x in ans {
        out.push_str(&format!("{} ", x ^ a));
    }
    out.pop();
    println!("{}", out);
}

fn main() {
    run();
}