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 Python (3.4.3) (judge verdict: Accepted)

def Double(vec):
	m=len(vec)
	res=[]
	for i in range(0,m,2):
		res.extend([vec[i],vec[i]^m,vec[i+1]^m,vec[i+1]])
	return res

def Greedy(n):
	m=1<<n
	res=[0]*m
	vis=[False]*m
	vis[0]=True
	for i in range(1,m):
		x=res[i-1]
		for j in range(n):
			if not vis[x^(1<<j)]:
				x^=1<<j
				break
		vis[x]=True
		res[i]=x
	return res

def Perfect(n):
	if n==1:
		return [0,1]
	m=1<<n
	A=Greedy(n-1)
	B=Double(Perfect(n-2))
	B.reverse()
	for i in range(m>>1):
		B[i]^=m-1
	A.extend(B)
	return A

n,a,b=map(int,input().split())
m=1<<n
c=bin(a^b).count('1')
if not c&1:
	print('NO')
	exit()
tmp=Perfect(c)
for i in range(c,n):
	tmp=Double(tmp)
p=0
q=c
ans=[0]*m
for i in range(n):
	if (a^b)>>i&1:
		for j in range(m):
			ans[j]^=(((tmp[j]>>p)^(a>>i))&1)<<i
		p+=1
	else:
		for j in range(m):
			ans[j]^=(((tmp[j]>>q)^(a>>i))&1)<<i
		q+=1
print('YES\n',' '.join(str(i) for i in ans),sep='')