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 C (GCC 5.4.1) (judge verdict: Accepted)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int a[(1<<17)+10];
int t[(1<<17)+10];

void f(int n){
	int k=1;
	int cnt=2;
	a[0]=0;
	a[1]=1;
	
	while(k<n){
		repp(i,0,1<<k,2){
			t[2*i  ]=a[i  ];
			t[2*i+1]=a[i  ]|(1<<k);
			t[2*i+2]=a[i+1]|(1<<k);
			t[2*i+3]=a[i+1];			
		}
		rep(i,0,1<<k)t[2*(1<<k)+i]=a[(1<<k)-1-i]|(2<<k);
		rep(i,0,1<<k)t[3*(1<<k)+i]=a[i]|(3<<k);
		rep(i,0,4<<k)a[i]=t[i];
		k+=2;
	}
	
}

int g(int n){return n^(n>>1);}

int n,S,G;
int ans[(1<<17)+10];

void puts2(int n,int digit){rep(cnt,0,digit)putchar(n&(1LL<<(digit-1-cnt))?49:48);putchar(10);}

int main(){
	scanf("%d%d%d",&n,&S,&G);
	int x=__builtin_popcount(S^G);
	if(x%2!=1){
		puts("NO");
		return 0;
	}

	puts("YES");
	f(x);
	if(x==n){
		rep(i,0,1<<n)printf("%lld ",a[i]^S);
		return 0;
	}
	
	int cnt=0;
	//00→a0→a1→01→02→…→
	repp(j,0,1<<x,2){
		rep(i,0,1<<(n-x))ans[cnt++]=(g(i)<<x)|a[j];
		rep(i,0,1<<(n-x))ans[cnt++]=(g((1<<(n-x))-1-i)<<x)|a[j+1];
	}

	rep(i,0,1<<n){
		//元の位置に振り分け
		int temp=0;
		int x0=0,x1=x;
		rep(j,0,n){
			if(bit(S^G,j)){
				temp|=bit(ans[i],x0)<<j;
				x0++;
			}else{
				temp|=bit(ans[i],x1)<<j;
				x1++;
			}
		}
		ans[i]=temp^S;
	}
	rep(i,0,1<<n)printf("%d ",ans[i]);
//	rep(i,(1<<n)-10,1<<n)puts2(ans[i],17);
//	rep(i,1,1<<n)printf("%d",__builtin_popcountll(ans[i]^ans[i-1]));
}