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 Ruby (2.3.3) (judge verdict: Wrong Answer)

N, A, B = gets.strip.split(/ /).collect{|x| x.to_i}

b_list = []
same_list = []
diff_list = []

bit = 1
N.times{|i|
	a = ((A & bit) != 0) ? 1 : 0
	b = ((B & bit) != 0) ? 1 : 0
	b_list << [a == b ? :same : :diff, a, b]
	if a == b
		same_list << i
	else
		diff_list << i
	end
	bit *= 2
}

#p b_list
#p same_list
#p diff_list

if diff_list.length % 2 == 0
	puts "NO"
	exit
else
	first_index = diff_list[0]
	list = b_list[first_index][1] == 0 ? [0, 1 << first_index] : [1 << first_index, 0]
	i = 1
	while i < diff_list.length
		i1 = diff_list[i]
		i2 = diff_list[i + 1]
		new_list = []
		a = b_list[i1][1]
		b = b_list[i2][1]
		zero = (a == 0)
		b1 = (1 << i1)
		b2 = (1 << i2)
		j = 0
		while j < list.length
			x = list[j]
			y = list[j + 1]
			new_list << b1 * a +       b2 * b + x
			new_list << b1 * (1 - a) + b2 * b + x
			new_list << b1 * (1 - a) + b2 * (1 - b) + x
			new_list << b1 * a +       b2 * (1 - b) + x
			new_list << b1 * a +       b2 * (1 - b) + y
			new_list << b1 * a +       b2 * b + y
			new_list << b1 * (1 - a) + b2 * b + y
			new_list << b1 * (1 - a) + b2 * (1 - b) + y
			j += 2
		end
		list = new_list
		i += 2
	end
	
	same_list.each{|i|
		a = b_list[i][1]
		bit = (1 << i)
		new_list = []
		zero = (a == 0)
		list.each{|x|
			if zero
				new_list << x
				new_list << (bit | x)
			else
				new_list << (bit | x)
				new_list << x
			end
			zero = !zero
		}
		list = new_list
	}
end

p list