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++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
struct P
{
    int x,y,z;
    bool operator<(const P &a)const{
        //if(y!=a.y) return y>a.y;
        return max(x,-x)>max(a.x,-a.x);

    }

};
vector<long long> v[211111];
//bitset<4001000> b;
int i,n,d,m,k,a,b,c,e;
int o[211133];
int l[211112];
long long j[211113];
int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<long long> s;

//priority_queue<P> q;
queue<P> q;
string r;
//char r[1];
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
map<int,int> p,p1;
//v.resize(unique(v.begin(),v.end())-v.begin());
/*struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> p;//safe_map;
*/
bool as(P a,P b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y<b.y;
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng();

int f(int n,int m)
{
    int k=0;
    for(;n||m;n/=2,m/=2)
        if(n%2!=m%2)k++;
    return k;
}

int main()
{
    scanf("%d %d %d",&a,&b,&c);
    a=2<<(a-1);
    a--;
    if(a<f(b,c)||a%2!=f(b,c)%2) puts("NO");
    else
    {
        puts("YES");
        printf("%d ",b);
        int t=1;
        for(;b!=c;t++)
        {
            int i=1;
            for(;f(b,c)<=f(b^i,c);i*=2);
            b^=i;
            printf("%d ",b);
        }
        for(;t<a;t++)
        {
            b^=1;
            printf("%d ",b);
        }
        printf("%d",c);
    }
}