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: Wrong Answer)

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::BTreeMap;

fn main() {
    input! {
        n: usize,
        a: usize,
        b: usize,
    }

    let mut gray = vec![0; 1 << n];

    for i in 0..gray.len() {
        gray[i] = i ^ (i >> 1);
    }

    let mut mm = BTreeMap::<(usize, usize), usize>::new();

    for i in 0..gray.len() {
        mm.insert((gray[i], gray[(i + 1) % gray.len()]), i);
    }

    let mut pos = None;

    for i in 0..n {
        for j in i..n {
            let aa = bswap(a, i, j);
            let bb = bswap(b, i, j);

            if let Some(p) = mm.get(&(aa, bb)) {
                pos = Some((false, p, i, j));
            } else if let Some(p) = mm.get(&(bb, aa)) {
                pos = Some((true, p, i, j));
            }
        }
    }

    // dbg!(&pos);

    if pos == None {
        println!("NO");
        return;
    }

    let (dir, pos, i, j) = pos.unwrap();

    println!("YES");

    for k in 0..gray.len() {
        if k > 0 {
            print!(" ");
        }
        if !dir {
            print!("{}", bswap(gray[(gray.len() + pos - k) % gray.len()], i, j));
        } else {
            print!("{}", bswap(gray[(pos + 1 + k) % gray.len()], i, j));
        }
    }
    println!();
}

fn bswap(a: usize, i: usize, j: usize) -> usize {
    (a & !(1 << i) & !(1 << j)) | ((a >> i) & 1) << j | ((a >> j) & 1) << i
}