Language: C++

#include <bits/stdc++.h>
 
#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
 
template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}
 
unsigned int popcnt(unsigned int x) {
    x = (x & 0x55555555) + ((x >>  1) & 0x55555555);
    x = (x & 0x33333333) + ((x >>  2) & 0x33333333);
    x = (x & 0x0F0F0F0F) + ((x >>  4) & 0x0F0F0F0F);
    x = (x & 0x00FF00FF) + ((x >>  8) & 0x00FF00FF);
    x = (x & 0x0000FFFF) + ((x >> 16) & 0x0000FFFF);
    return x;
}
 
unsigned int ntz(unsigned int x) {
    unsigned int n = 1;
    if ((x & 0x0000FFFFull) == 0) { n += 16; x >>= 16; }
    if ((x & 0x000000FFull) == 0) { n +=  8; x >>=  8; }
    if ((x & 0x0000000Full) == 0) { n +=  4; x >>=  4; }
    if ((x & 0x00000003ull) == 0) { n +=  2; x >>=  2; } 
    return n - (x & 1);
}
 
unsigned int low_bit(unsigned int x, int k) {
    return x & ((1 << k) - 1);
}
 
unsigned int high_bit(unsigned int x, int k) {
    return x & (~((1 << k) - 1));
}
 
 
vector<int> f(int N, int A, int B) {
    vector<int> P(1 << N);
    if (N == 1) {
        P[0] = A;
        P[1] = B;
        return P;
    }
    int x = ntz(A ^ B);
    int A0 = (high_bit(A, x + 1) >> 1) ^ low_bit(A, x);
    int B0 = (high_bit(B, x + 1) >> 1) ^ low_bit(B, x);
    int C;
    if (A0 & 1) {
        C = A0 - 1;
    } else {
        C = A0 + 1;
    }
    vector<int> Q = f(N - 1, A0, C);
    vector<int> R = f(N - 1, C, B0);
    REP(i, 1 << (N - 1)) {
        P[i]                  = (high_bit(Q[i], x) << (x + 1)) ^ (A & (1 << x)) ^ low_bit(Q[i], x);
        P[(1 << (N - 1)) + i] = (high_bit(R[i], x) << (x + 1)) ^ (B & (1 << x)) ^ low_bit(R[i], x);
    }
    return P;
}
 
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, A, B;
    cin >> N >> A >> B;
    
    if (abs(popcnt(A) - popcnt(B)) % 2 == 0) {
        cout << "NO\n";
    } else {
        cout << "YES\n";
        vector<int> P = f(N, A, B);
        REP(i, (1 << N)) {
            if (i != 0) {
                cout << " ";
            }
            cout << P[i];
        }
        cout << "\n";
    }
    cout << flush;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:92:12: error: call of overloaded 'abs(unsigned int)' is ambiguous
   92 |     if (abs(popcnt(A) - popcnt(B)) % 2 == 0) {
      |         ~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:42,
                 from a.cc:1:
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
In file included from /usr/include/c++/14/cstdlib:81:
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~