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: Accepted)

use std::io;
use std::io::BufRead;

const MOD: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new(std::io::stdin());
    let n: usize = sc.next().unwrap();
    let a: usize = sc.next().unwrap();
    let b: usize = sc.next().unwrap();
    let c = a^b;
    if c.count_ones() % 2 == 0 {
        println!("NO");
        return;
    }
    println!("YES");
    let res = recur(c, n);

    for i in 0..(1<<n)-1 {
        if (res[i] ^ res[i+1]).count_ones() != 1 {
            panic!();
        }
    }

    let mut first = true;
    for r in res.into_iter() {
        if !first {
            print!(" ");
        }
        print!("{}", r ^ a);
        first = false;
    }
    println!();

}

fn recur(c: usize, n: usize) -> Vec<usize> {
    if c >= (1<<n) {
        panic!("{} {}", c, n);
    }
    if c == 0 {
        panic!("zero");
    }
    if n == 1 {
        return vec![0, 1];
    }
    let mut pos = n;
    let mut nc = c;
    for i in 0..n {
        if ((c >> i) & 1) == 1 {
            pos = i;
            nc = (c & ((1<<i)-1)) | ((c >> i + 1) << i);
            break;
        }
    }
    let mut last = recur(nc ^ 1, n-1);
    for i in 0..1<<n-1 {
        last[i] ^= 1;
    }
    let first = recur(last[0], n-1);

    let mut res = vec![0; 1<<n]; 
    for i in 0..1<<n {
        if i < 1<<n-1 {
            res[i] = first[i];
        } else {
            res[i] = last[i - (1<<n-1)] ^ (1<<n-1);
        }
    }
    for i in 0..1<<n {
        res[i] = ((res[i] & ((1<<n-1)-1)) >> pos << (pos + 1)) | (res[i] >> n-1 << pos) | (res[i] & ((1<<pos)-1));
    }
    res
}


/// Scanner
///
/// # Example
/// ```
/// use contest::io::scanner;
/// let mut sc = scanner::Scanner::new("1 2 \n\n \r\t \n 3.5".as_bytes());
/// assert_eq!("1".to_string(), sc.next::<String>().unwrap());
/// assert_eq!(2, sc.next());
/// assert_eq!(3.5, sc.next());
/// assert_eq!(None, sc.next::<i32>());
/// ```

pub struct Scanner<R: io::Read> {
    br: io::BufReader<R>,
    // Read tokens are stored in reversed order per line.
    buf: Vec<String>,
}

impl<R: io::Read> Scanner<R> {
    pub fn new(r: R) -> Scanner<R> {
        Scanner {
            br: io::BufReader::new(r),
            buf: vec![],
        }
    }
    #[inline]
    pub fn next<T>(&mut self) -> Option<T>
        where T: std::str::FromStr,
              T::Err: std::fmt::Debug
    {
        self.next_string().map(|s| s.parse::<T>().expect("Parse failed: "))
    }
    fn next_string(&mut self) -> Option<String> {
        self.buf.pop().or_else(|| match self.update() {
            true => self.next_string(),
            false => None,
        })
    }
    #[inline]
    fn update(&mut self) -> bool {
        let mut s = String::new();
        let res = self.br.read_line(&mut s);
        match res.expect("I/O error.") {
            0 => false,
            _ => {
                self.buf = s.split_whitespace().map(|x| x.to_string()).rev().collect();
                true
            }
        }
    }
}