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 PyPy3 (2.4.0) (judge verdict: Wrong Answer)

import sys
input = sys.stdin.readline
N,A,B=map(int,input().split())
if N==1:
    print('YES')
    print(A,B)
    sys.exit()
C=A^B
C=bin(C)[2:]
num=0
for i in range(len(C)):
    if C[i]=='1':
        num+=1
if num%2==0:
    print('NO')
    sys.exit()
def f(a,b,n):
    if n==1:
        return [a,b]
    for i in range(n):
        if a&(1<<i)!=b&(1<<i):
            break
    x=(((1<<i)-1)&a)+((a>>(i+1))<<i)
    y = (((1 << i) - 1) & b) + ((b >> (i + 1)) << i)

    for z in range(1<<(n)):
        if x!=z and y!=z and bin(x^z).count('1')==1 and bin(y^z).count('1')==1:
            break
    #print(i,a,b,x,y,z)
    L=f(x,z,n-1)
    M=f(z,y,n-1)
    dp=[0]*(2*len(L))
    num=0
    for l in L:
        dp[num]=(((1<<i)-1)&l)+((l>>i)<<(i+1))+(a&(1<<i))
        num+=1
    for l in M:
        dp[num]=(((1<<i)-1)&l)+((l>>i)<<(i+1))+(b&(1<<i))
        num+=1
    #print(L,M,dp,i,a,b,x,y,z)
    return dp

L=f(A,B,N)
print('YES')
print(' '.join(map(str,L)))
#for i in range(len(L)-1):
    #s=bin(L[i]^L[i+1]).count('1')
    #print(bin(L[i]))
    #if s!=1:
        #print(i)
#print(len(set(L)))