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: Wrong Answer)

#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 dp[(1<<17)+10];
int a[(1<<17)+10];

void f(int n){
	rep(i,0,1<<n)dp[i]=0;
	rep(i,0,1<<n)a[i]=0;	

	dp[0]=1;

	int s=0;
	int cnt=1;
	int flag=1;
	while(flag){
		flag=0;
		rep(i,0,n)if((s^(1<<i))!=(1<<n)-1&&!dp[s^(1<<i)]){
			dp[s^(1<<i)]=1;
			a[cnt++]=s^=1<<i;
			flag=1;
			break;
		}
	}
	a[cnt]=(1<<n)-1;
}

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

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

int main(){
	scanf("%lld%lld%lld",&n,&S,&G);
	ll x=__builtin_popcountll(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++;
			}
		}
		printf("%d ",temp^S);
	}
}