Problem:
D: XORANDORBAN
Problem Statement
You are given a positive integer
N
. Your task is to determine a set
S
of
2^N
integers satisfying the following conditions:
All the integers in
S
are at least
0
and less than
2^{N+1}
.
All the integers in
S
are distinct.
You are also given three integers
X
,
A
, and
O
, where
0 \leq X, A, O < 2^{N+1}
. Then, any two integers (
a
,
b
) in
S
must satisfy
a
{\it xor}
b \neq X
,
a
{\it and}
b \neq A
,
a
{\it or}
b \neq O
, where
{\it xor}
,
{\it and}
,
{\it or}
are
bitwise xor
,
bitwise and
,
bitwise or
, respectively. Note that
a
and
b
are not necessarily different.
Input
N
X
A
O
Constraints
1 \leq N \leq 13
0 \leq X, A, O < 2^{N+1}
Inputs consist only of integers.
Output
If there is no set satisfying the conditions mentioned in the problem statement, output
No
in a line. Otherwise, output
Yes
in the first line, and then output
2^N
integers in such a set in the second line. If there are multiple sets satisfying the conditions, you can output any of them.
Sample Input 1
2 6 1 5
Output for Sample Input 1
Yes
0 3 4 7
Sample Input 2
3 0 5 1
Output for Sample Input 2
No
Sample Input 3
3 4 2 5
Output for Sample Input 3
Yes
1 0 6 15 8 9 14 7

Submitted solutions:

code_snippet: /*program by mangoyang*/
#pragma GCC optimize("Ofast", "inline")
#include<bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
    int ch = 0, f = 0; x = 0;
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    if(f) x = -x;
}
const int N = 5000005;
vector<int> g[N];
int dfn[N], low[N], id[N], vis[N], st[N], Index, top, ID;
int A, B, C, n;
inline void tarjan(int u){
    low[u] = dfn[u] = ++Index, st[++top] = u, vis[u] = 1;
    for(auto v : g[u]) if(!dfn[v]){
        tarjan(v);
        low[u] = min(low[v], low[u]);
    }
    else if(vis[v]) low[u] = min(low[u], dfn[v]);
    if(low[u] == dfn[u]){
        ++ID;
        while(st[top] != u) 
            id[st[top]] = ID, vis[st[top]] = 0, top--;
        id[u] = ID, vis[u] = 0, top--;
    }
}
int main(){
    read(n), read(A), read(B), read(C), n++;
    int ss = 1 << n;
    for(int s = 0; s < ss; s++){
        g[s+1].push_back((s ^ A) + ss + 1);
        g[s+ss+1].push_back((s ^ A) + 1);
    }
    for(int s = 0; s < (1 << n); s++) if((s & B) == B){
        int S2 = ((1 << n) - 1) ^ s;
        for(int T = S2; T; T = (T - 1) & S2)
            g[s+1].push_back((T | B) + ss + 1);
        g[s+1].push_back(B + ss + 1);
    }
    for(int s = 0; s < (1 << n); s++) if((s | C) == C){
        int S2 = s;
        for(int T = S2; T; T = (T - 1) & S2)
            g[s+1].push_back((T | (C ^ s)) + ss + 1);
        g[s+1].push_back((C ^ s) + ss + 1);
    }
    for(int i = 1; i <= 2 * ss; i++) if(!dfn[i]) tarjan(i);
    for(int i = 0; i < ss; i++)
        if(id[i+1] == id[i+ss+1]) return puts("No"), 0;
    puts("Yes");
    vector<int> Ans;
    for(int i = 0; i < ss; i++)
        if(id[i+1] < id[i+ss+1]) Ans.push_back(i);
    for(int i = 0; i < (int) Ans.size(); i++){
        printf("%d", Ans[i]);
        if(i < (int) Ans.size() - 1) putchar(' ');
    }
    puts("");
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 200984
final_rank: 9

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rrep(i, a, b) for (ll i = (ll)(b)-1; i >= (ll)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

struct SCC{
    int n,m,cur;
    vector<vector<int>> g;
    vector<int> low,ord,id;
    SCC(int _n=0):n(_n),m(0),cur(0),g(_n),low(_n),ord(_n,-1),id(_n){}
    void resize(int _n){
        n=_n;
        g.resize(n);
        low.resize(n);
        ord.resize(n,-1);
        id.resize(n);
    }
    void add_edge(int u,int v){g[u].emplace_back(v);}
    void dfs(int v,vector<int>& used){
        ord[v]=low[v]=cur++;
        used.emplace_back(v);
        for(auto& nxt:g[v]){
            if(ord[nxt]==-1){
                dfs(nxt,used); chmin(low[v],low[nxt]);
            }
            else{
                chmin(low[v],ord[nxt]);
            }
        }
        if(ord[v]==low[v]){
            while(1){
                int add=used.back(); used.pop_back();
                ord[add]=n; id[add]=m;
                if(v==add)break;
            }
            m++;
        }
    }
    void run(){
        vector<int> used;
        rep(v,0,n)if(ord[v]==-1)dfs(v,used);
        for(auto& x:id)x=m-1-x;
    }
};

/**
 * @brief Strongly Connected Components
 */

int main() {
    int N;
    cin >> N;
    N++;
    int X, A, O;
    cin >> X >> A >> O;
    if (X == 0) {
        cout << "No" << endl;
        return 0;
    }
    SCC G(1<<N);
    auto NGPair = [&](int i, int j) -> void {
        G.add_edge(i,j^X);
        G.add_edge(j,i^X);
    };
    for (int i = (1<<N) - 1 - A; ; i = (i-1)&((1<<N)-1-A)) {
        for (int j = (1<<N) - 1 - A - i; ; j = (j-1)&((1<<N)-1-A-i)) {
            NGPair(i+A,j+A);
            if (j == 0) break;
        }
        if (i == 0) break;
    }
    for (int i = O; ; i = (i-1)&O) {
        for (int j = i; ; j = (j-1)&i) {
            NGPair(i,j+O-i);
            if (j == 0) break;
        }
        if (i == 0) break;
    }
    G.run();
    vector<int> ANS;
    vector<bool> used(1<<N,false);
    rep(i,0,1<<N) {
        if (used[i]) continue;
        if (G.id[i] == G.id[i^X]) {
            cout << "No" << endl;
            return 0;
        }
        used[i] = used[i^X] = true;
        if (G.id[i] < G.id[i^X]) ANS.push_back(i^X);
        else ANS.push_back(i);
    }
    cout << "Yes" << endl;
    rep(i,0,1<<(N-1)) {
        cout << ANS[i] << (i==((1<<(N-1))-1) ? '\n' : ' ');
    }
}
accuracy: 1
time_ms: 170
memory_kb: 128344
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;


#include <algorithm>
#include <utility>
#include <vector>

namespace atcoder {
namespace internal {

template <class E> struct csr {
    std::vector<int> start;
    std::vector<E> elist;
    csr(int n, const std::vector<std::pair<int, E>>& edges)
        : start(n + 1), elist(edges.size()) {
        for (auto e : edges) {
            start[e.first + 1]++;
        }
        for (int i = 1; i <= n; i++) {
            start[i] += start[i - 1];
        }
        auto counter = start;
        for (auto e : edges) {
            elist[counter[e.first]++] = e.second;
        }
    }
};

// Reference:
// R. Tarjan,
// Depth-First Search and Linear Graph Algorithms
struct scc_graph {
  public:
    scc_graph(int n) : _n(n) {}

    int num_vertices() { return _n; }

    void add_edge(int from, int to) { edges.push_back({from, {to}}); }

    // @return pair of (# of scc, scc id)
    std::pair<int, std::vector<int>> scc_ids() {
        auto g = csr<edge>(_n, edges);
        int now_ord = 0, group_num = 0;
        std::vector<int> visited, low(_n), ord(_n, -1), ids(_n);
        visited.reserve(_n);
        auto dfs = [&](auto self, int v) -> void {
            low[v] = ord[v] = now_ord++;
            visited.push_back(v);
            for (int i = g.start[v]; i < g.start[v + 1]; i++) {
                auto to = g.elist[i].to;
                if (ord[to] == -1) {
                    self(self, to);
                    low[v] = std::min(low[v], low[to]);
                } else {
                    low[v] = std::min(low[v], ord[to]);
                }
            }
            if (low[v] == ord[v]) {
                while (true) {
                    int u = visited.back();
                    visited.pop_back();
                    ord[u] = _n;
                    ids[u] = group_num;
                    if (u == v) break;
                }
                group_num++;
            }
        };
        for (int i = 0; i < _n; i++) {
            if (ord[i] == -1) dfs(dfs, i);
        }
        for (auto& x : ids) {
            x = group_num - 1 - x;
        }
        return {group_num, ids};
    }

    std::vector<std::vector<int>> scc() {
        auto ids = scc_ids();
        int group_num = ids.first;
        std::vector<int> counts(group_num);
        for (auto x : ids.second) counts[x]++;
        std::vector<std::vector<int>> groups(ids.first);
        for (int i = 0; i < group_num; i++) {
            groups[i].reserve(counts[i]);
        }
        for (int i = 0; i < _n; i++) {
            groups[ids.second[i]].push_back(i);
        }
        return groups;
    }

  private:
    int _n;
    struct edge {
        int to;
    };
    std::vector<std::pair<int, edge>> edges;
};

}  // namespace internal

}  // namespace atcoder

#include <cassert>
#include <vector>

namespace atcoder {

// Reference:
// B. Aspvall, M. Plass, and R. Tarjan,
// A Linear-Time Algorithm for Testing the Truth of Certain Quantified Boolean
// Formulas
struct two_sat {
  public:
    two_sat() : _n(0), scc(0) {}
    two_sat(int n) : _n(n), _answer(n), scc(2 * n) {}

    void add_clause(int i, bool f, int j, bool g) {
        assert(0 <= i && i < _n);
        assert(0 <= j && j < _n);
        scc.add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0));
        scc.add_edge(2 * j + (g ? 0 : 1), 2 * i + (f ? 1 : 0));
    }
    bool satisfiable() {
        auto id = scc.scc_ids().second;
        for (int i = 0; i < _n; i++) {
            if (id[2 * i] == id[2 * i + 1]) return false;
            _answer[i] = id[2 * i] < id[2 * i + 1];
        }
        return true;
    }
    std::vector<bool> answer() { return _answer; }

  private:
    int _n;
    std::vector<bool> _answer;
    internal::scc_graph scc;
};

}  // namespace atcoder

using namespace atcoder;
using ll = long long;

int main() {
    ll N,X,A,O;
    cin>>N>>X>>A>>O;
    if(X==0){
        cout<<"No"<<endl;
        return 0;
    }
    vector<ll> BN(1<<(N+1),0),NB(1<<(N+1),0);
    ll cnt=0;
    for(ll i=0;i<(1<<(N+1));i++){
        if(BN[i]!=0)continue;
        BN[i]=cnt+1;
        BN[i^X]=-(cnt+1);
        NB[cnt*2]=i;
        NB[cnt*2+1]=i^X;
        cnt++;
    }
    two_sat T(1<<N);
    ll M=(1<<N);
    for(ll a=0;a<(1<<(N+1));a++){
        if((a&A)==A){
            ll bit=0,dit=0;
            for(ll k=0;k<N+1;k++){
                if(a&(1<<k)){
                    if(A&(1<<k)){
                        dit+=(1<<k);
                    }
                }
                else{
                    if(A&(1<<k)){}
                    else{
                        bit+=(1<<k);
                    }
                }
            }
            for (ll u = bit; u >= 0; u = (u - 1) & bit) {
		        ll b=u+dit;
                T.add_clause(
                    (BN[a]>0?BN[a]-1:-BN[a]-1),
                    BN[a]<0,
                    (BN[b]>0?BN[b]-1:-BN[b]-1),
                    BN[b]<0
                );
                if (u == 0)break;
            }
        }
        if((a|O)==O){
            ll bit=0,dit=0;
            for(ll k=0;k<N+1;k++){
                if(a&(1<<k)){
                    if(O&(1<<k)){
                        bit+=(1<<k);
                    }
                }
                else{
                    if(O&(1<<k)){dit+=(1<<k);}
                    
                }
            }
            for (ll u = bit; u >= 0; u = (u - 1) & bit) {
		        ll b=u+dit;
                T.add_clause(
                    (BN[a]>0?BN[a]-1:-BN[a]-1),
                    BN[a]<0,
                    (BN[b]>0?BN[b]-1:-BN[b]-1),
                    BN[b]<0
                );
                if (u == 0)break;
            }
        }
    }
    if(!T.satisfiable()){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    vector<bool> AN=T.answer();
    for(ll i=0;i<(1<<N);i++){
        ll a=(AN[i]?NB[i*2]:NB[i*2+1]);
        cout<<a<<" \n"[i==(1<<N)-1];
    }
}
accuracy: 1
time_ms: 260
memory_kb: 265956
final_rank: 12

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

vector<int> scc(const vector<vector<int>> &g) {
    int n = (int)g.size();
    int cnt = 0;
    vector<vector<int>> rg(n);
    vector<int> order;
    vector<int> res(n, -1);
    vector<bool> used(n);
    for (int i = 0; i < n; ++i) {
        for (int j : g[i])
            rg[j].push_back(i);
    }

    auto dfs1 = [&](auto self, int s) -> void {
        used[s] = true;
        for (int t : g[s]) {
            if (!used[t]) self(self, t);
        }
        order.push_back(s);
    };
    auto dfs2 = [&](auto self, int s) -> void {
        for (int t : rg[s]) {
            if (res[t] == -1) {
                res[t] = res[s];
                self(self, t);
            }
        }
    };

    order.reserve(n);
    for (int i = 0; i < n; ++i) {
        if (!used[i]) {
            dfs1(dfs1, i);
        }
    }
    reverse(order.begin(), order.end());
    for (int i : order) {
        if (res[i] == -1) {
            res[i] = cnt++;
            dfs2(dfs2, i);
        }
    }
    return res;
}

struct twosat {
    int n;
    vector<vector<int>> g;
    twosat(int n) : n(n), g(2 * n) {}

    // (i = f1) || (j = f2)
    void add_clause(int i, bool f1, int j, bool f2) {
        g[(i << 1) ^ !f1].emplace_back((j << 1) ^ f2);
        g[(j << 1) ^ !f2].emplace_back((i << 1) ^ f1);
    }

    // (i = f1) -> (j = f2) <=> (i = !f1) || (j = f2)
    void add_if(int i, bool f1, int j, bool f2) { add_clause(i, !f1, j, f2); }

    // i
    void set_true(int i) { add_clause(i, true, i, true); }
    // !i
    void set_false(int i) { add_clause(i, false, i, false); }

    // ABC210-F
    // vを満たすものは高々1個である
    // 補助頂点を追加し、条件を既に満たしていたら1とする累積状態を表す
    void set_atmost_one(vector<pair<int, bool>> &v) {
        if (v.size() <= 1) return;
        int pre = -1;
        for (auto [x, f] : v) {
            g.emplace_back();
            g.emplace_back();
            int cur = n++;
            add_if(x, f, cur, 1);
            if (pre != -1) {
                add_if(pre, 1, cur, 1);
                add_clause(x, !f, pre, 0);
            }
            pre = cur;
        }
    }

    vector<bool> solve() {
        vector<int> c = scc(g);
        vector<bool> res(n);
        for (int i = 0; i < n; ++i) {
            if (c[i << 1] == c[i << 1 | 1]) return vector<bool>();
            res[i] = (c[i << 1] < c[i << 1 | 1]);
        }
        return res;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, X, A, O;
    cin >> n >> X >> A >> O;
    if (X == 0) {
        cout << "No" << endl;
        return 0;
    }
    int m = (1 << (n + 1));
    twosat slv(m);
    for (int i = 0; i < m; ++i) {
        int j = (i ^ X);
        if (i < j) {
            slv.add_clause(i, true, j, true);
            slv.add_clause(i, false, j, false);
        }
    }
    for (int i = 0; i < m; ++i) {
        for (int j = i; j < m; ++j) {
            if ((i & j) == A) {
                slv.add_clause(i, false, j, false);
            }
            if ((i | j) == O) {
                slv.add_clause(i, false, j, false);
            }
        }
    }
    auto res = slv.solve();
    if (!res.size()) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        bool f = true;
        for (int i = 0; i < res.size(); ++i) {
            if (res[i]) {
                if (!f) cout << " ";
                cout << i;
                f = false;
            }
        }
        cout << endl;
    }
}
accuracy: 1
time_ms: 240
memory_kb: 144240
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rng(i, l, r) for(int i = int(l); i < int(r); i++)
#define rep(i, n) rng(i, 0, n)
#define sz(v) int(v.size())
#define foa(s, v) for(auto &s : v)
#define all(v) v.begin(), v.end()

using vi = vector<int>;
using pii = pair<int, int>;

struct two_sat {
	int N;
	vector<vi> gr;
	vi values;

	two_sat(int n = 0) : N(n), gr(2 * n) {}

	void either(int f, int j) {
		f = max(2 * f, -1 - 2 * f);
		j = max(2 * j, -1 - 2 * j);
		gr[f].push_back(j ^ 1);
		gr[j].push_back(f ^ 1);
	}
	void not_and(int f, int j) { either(~f, ~j); }
	void set_value(int x) { either(x, x); }

	vi val, comp, z;
	int time = 0;
	int dfs(int i) {
		int low = val[i] = ++time, x;
		z.push_back(i);
		for(int e : gr[i])
			if(!comp[e]) low = min(low, val[e] ?: dfs(e));
		if(low == val[i]) do {
				x = z.back();
				z.pop_back();
				comp[x] = low;
				if(values[x >> 1] == -1) values[x >> 1] = x & 1;
			} while(x != i);
		return val[i] = low;
	}

	bool solve() {
		values.assign(N, -1);
		val.assign(2 * N, 0);
		comp = val;
		rep(i, 2 * N) if(!comp[i]) dfs(i);
		rep(i, N) if(comp[2 * i] == comp[2 * i + 1]) return 0;
		return 1;
	}
};

int n;
void solve() {
	int x, a, o;
	cin >> x >> a >> o;
	if(!x) {
		cout << "No\n";
		return;
	}
	vector<pii> pi;
	vector<int> out(1 << (n + 1));

	rep(i, 1 << (n + 1)) {
		if(out[i]) continue;
		int u = i;
		int v = i ^ x;
		out[u] = out[v] = 1;
		pi.emplace_back(u, v);
	}

	int N = 1 << n;
	assert(sz(pi) == N);
	two_sat ts(N);
	// true:first
	// false:second
	rep(i, N) {
		auto [ti, fi] = pi[i];
		if(ti == a or ti == o) {
			ts.set_value(~i);
		}
		if(fi == a or fi == o) {
			ts.set_value(i);
		}
		rng(j, i + 1, N) {
			auto [tj, fj] = pi[j];
			if((ti & tj) == a or (ti | tj) == o) {
				ts.not_and(i, j);
			}

			if((ti & fj) == a or (ti | fj) == o) {
				ts.not_and(i, ~j);
			}

			if((fi & tj) == a or (fi | tj) == o) {
				ts.not_and(~i, j);
			}

			if((fi & fj) == a or (fi | fj) == o) {
				ts.not_and(~i, ~j);
			}
		}
	}

	auto ans = ts.solve();
	if(ans) {
		cout << "Yes\n";
		vector<int> st;
		rep(i, N) {
			if(ts.values[i]) {
				st.push_back(pi[i].first);
			} else {
				st.push_back(pi[i].second);
			}
		}
		sort(all(st));
		rep(i, N) { cout << st[i] << " \n"[i == N - 1]; }
	} else {
		cout << "No\n";
	}
}
int main() {
	while(cin >> n && n) solve();
}
accuracy: 1
time_ms: 150
memory_kb: 69324
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rng(i, l, r) for(int i = int(l); i < int(r); i++)
#define rep(i, n) rng(i, 0, n)
#define sz(v) int(v.size())
#define foa(s, v) for(auto &s : v)
#define all(v) v.begin(), v.end()

using vi = vector<int>;
using pii = pair<int, int>;

struct two_sat {
	int N;
	vector<vi> gr;
	vi values;

	two_sat(int n = 0) : N(n), gr(2 * n) {}

	void either(int f, int j) {
		f = max(2 * f, -1 - 2 * f);
		j = max(2 * j, -1 - 2 * j);
		gr[f].push_back(j ^ 1);
		gr[j].push_back(f ^ 1);
	}
	void not_and(int f, int j) { either(~f, ~j); }
	void set_value(int x) { either(x, x); }

	vi val, comp, z;
	int time = 0;
	int dfs(int i) {
		int low = val[i] = ++time, x;
		z.push_back(i);
		for(int e : gr[i])
			if(!comp[e]) low = min(low, val[e] ?: dfs(e));
		if(low == val[i]) do {
				x = z.back();
				z.pop_back();
				comp[x] = low;
				if(values[x >> 1] == -1) values[x >> 1] = x & 1;
			} while(x != i);
		return val[i] = low;
	}

	bool solve() {
		values.assign(N, -1);
		val.assign(2 * N, 0);
		comp = val;
		rep(i, 2 * N) if(!comp[i]) dfs(i);
		rep(i, N) if(comp[2 * i] == comp[2 * i + 1]) return 0;
		return 1;
	}
};

int n;
void solve() {
	int x, a, o;
	cin >> x >> a >> o;
	if(!x) {
		cout << "No\n";
		return;
	}
	vector<pii> pi;
	vector<int> out(1 << (n + 1));

	rep(i, 1 << (n + 1)) {
		if(out[i]) continue;
		int u = i;
		int v = i ^ x;
		out[u] = out[v] = 1;
		pi.emplace_back(u, v);
	}

	int N = 1 << n;
	assert(sz(pi) == N);
	two_sat ts(N);
	// true:first
	// false:second
	rep(i, N) {
		auto [ti, fi] = pi[i];
		rng(j, i + 1, N) {
			auto [tj, fj] = pi[j];
			if((ti & tj) == a or (ti | tj) == o) {
				ts.not_and(i, j);
			}

			if((ti & fj) == a or (ti | fj) == o) {
				ts.not_and(i, ~j);
			}

			if((fi & tj) == a or (fi | tj) == o) {
				ts.not_and(~i, j);
			}

			if((fi & fj) == a or (fi | fj) == o) {
				ts.not_and(~i, ~j);
			}
		}
	}

	auto ans = ts.solve();
	if(ans) {
		cout << "Yes\n";
		vector<int> st;
		rep(i, N) {
			if(ts.values[i]) {
				st.push_back(pi[i].first);
			} else {
				st.push_back(pi[i].second);
			}
		}
		sort(all(st));
		rep(i, N) { cout << st[i] << " \n"[i == N - 1]; }
	} else {
		cout << "No\n";
	}
}
int main() {
	while(cin >> n && n) solve();
}
accuracy: 0.27419354838709675
time_ms: 80
memory_kb: 4048
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using db = double;
using vi = vector<int>;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define debug(x) cout << #x <<"	"<< x <<endl
const int inf = 0x3f3f3f3f;
const db eps = 1e-8;
const int mod = 1e9+7;
ll qpow(ll a, ll b){
    ll ret = 1;
    while(b){
        if(b&1)ret = ret*a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return ret;
}
const int maxn = 2e5+7;
vi G[maxn];
//tarjan 强连通分量
int cnt, dfn[maxn], low[maxn], st[maxn], bel[maxn], top, ind;
bool ins[maxn];
void tarjan(int u){
    dfn[u] = low[u] = ++ind;
    ins[u] = 1;
    st[++top] = u;
    for(auto v: G[u]){
        if(!dfn[v]){
            tarjan(v);
            low[u] = min(low[u], low[v]);
        }else if (ins[v]){
            low[u] = min(low[u], low[v]);
        }
    }
    if(dfn[u]==low[u]){
        ++cnt;
        while(true){
            bel[st[top]] = cnt;
            ins[st[top]] = 0;
            if(st[top--]==u)break;
        }
    }
}
int n,a,o,x;
int main()
{
    scanf("%d%d%d%d", &n, &x, &a, &o);
    if(x==0){
        return puts("No"), 0;
    }
    int p = (1<<(n+1));
    for(int i=0; i<p; ++i){
        for(int j=i; j<p; ++j){
            if((i&j)==a){
                G[i].pb(j^x);
                G[j].pb(i^x);
            }
            if((i|j )== o){
                G[i].pb(j^x);
                G[j].pb(i^x);
            }
        }
    }
    for(int i=0; i<p; ++i){
        if(!dfn[i])tarjan(i);
    }
    vi ans;
    for(int i=0; i<p; ++i){
        if(bel[i]==bel[i^x]){
            return puts("No"), 0;
        }else if(bel[i]<bel[i^x])ans.pb(i);
    }
    puts("Yes");
    for(int i=0; i<p/2; ++i){
        printf("%d%c", ans[i], " \n"[i==p/2-1]);
    }
    return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 73488
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
// head

const int N=201000;

VI e[N];
int n,cnt,dfn[N],low[N],st[N],bel[N],top,ind;
bool ins[N];
int x,a,o;
void tarjan(int u) {
	dfn[u]=low[u]=++ind;
	ins[u]=1;
	st[++top]=u;
	rep(i,0,SZ(e[u])) {
		int v=e[u][i];
		if (!dfn[v]) tarjan(v),low[u]=min(low[u],low[v]);
		else if (ins[v]) low[u]=min(low[u],low[v]);
	} 
	if (dfn[u]==low[u]) {
		++cnt;
		while (1) {
			bel[st[top]]=cnt;
			ins[st[top]]=0;
			if (st[top--]==u) break;
		}
	}
}

int main() {
	scanf("%d%d%d%d",&n,&x,&a,&o);
	if (x==0) {
		puts("No");
		return 0;
	}
	int m=1<<(n+1);
	rep(i,0,m) rep(j,i,m) {
		if ((i&j)==a) {
			e[i].pb(j^x);
			e[j].pb(i^x);
		}
		if ((i|j)==o) {
			e[i].pb(j^x);
			e[j].pb(i^x);
		}
	}
	rep(i,0,m) if (!dfn[i]) tarjan(i);
	VI ans;
	rep(i,0,m) {
		if (bel[i]==bel[i^x]) {
			puts("No");
			return 0;
		}
		if (bel[i]<bel[i^x]) ans.pb(i);
	}
	puts("Yes");
	rep(i,0,(m/2)) printf("%d%c",ans[i]," \n"[i==m/2-1]);
}
accuracy: 1
time_ms: 170
memory_kb: 73788
final_rank: 2

code_snippet: #include <cstdio>
#include <vector>

using namespace std;
const int S = 1 << 14;

int n, A, X, O;
int U;
vector<int> G[S];

int dfn[S], low[S], timer;
int stk[S], top; bool inS[S];
int cmp[S], scc;
void tarjan(int x) {
    dfn[x] = low[x] = ++timer;
    inS[stk[++top] = x] = true;
    for (auto y : G[x]) {
        if (!dfn[y]) tarjan(y), low[x] = min(low[x], low[y]);
        else if (inS[y]) low[x] = min(low[x], dfn[y]);
    }
    if (low[x] == dfn[x]) {
		++scc;
		do {
			x = stk[top--];
			inS[x] = false, cmp[x] = scc;
		} while (low[x] != dfn[x]);
	}
}

int select[S];
signed main() {
    scanf("%d%d%d%d", &n, &X, &A, &O);
    U = 1 << (n + 1);

    for (int i = 0; i < U; i++) {
        if ((A & i) == A) {
            int j = (~i) & (U - 1);
            for (int k = j; ; k = (k - 1) & j) {
                int p = A | k;
                G[p].push_back(i ^ X);
                G[i].push_back(p ^ X);
                if (!k) break;
            }
        }
        if ((O | i) == O) {
            int j = i;
            for (int k = j; ; k = (k - 1) & j) {
                int p = (O ^ i) | k;
                G[p].push_back(i ^ X);
                G[i].push_back(p ^ X);
                if (!k) break;
            }
        }
    }

    for (int i = 0; i < U; i++)
        if (!dfn[i]) tarjan(i);
    
    for (int i = 0; i < U; i++)
        if (cmp[i] == cmp[i ^ X]) {
            puts("No");
            return 0;
        }
    
    puts("Yes");
    vector<int> ans;

    for (int i = 0; i < U; i++)
        if (cmp[i] < cmp[i ^ X])
            ans.push_back(i);
    
    for (int i = 0; i < (int)ans.size() - 1; i++)
        printf("%d ", ans[i]);

    return printf("%d\n", ans.back()), 0;
}
accuracy: 1
time_ms: 180
memory_kb: 138852
final_rank: 8

code_snippet: #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
typedef int ll;
typedef unsigned un;
typedef std::string str;
typedef std::pair<ll,ll> pll;
ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return f*x;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
void umax(ll& a,ll t){if(t>a)a=t;}
void umin(ll& a,ll t){if(t<a)a=t;}
const ll INF=1ll<<28;
#define MAXN 200011
std::vector<ll>g[MAXN];
ll dfn[MAXN],low[MAXN],scnt=0,scc[MAXN],cur=0;
ll s[MAXN],top=0;
bool ins[MAXN];
void tarjan(ll u)
{
	s[++top]=u,ins[u]=1;
	dfn[u]=low[u]=++cur;
	for(auto v:g[u])
	{
		if(!dfn[v])tarjan(v),umin(low[u],low[v]);
		else if(ins[v])umin(low[u],dfn[v]);
	}
	if(dfn[u]==low[u])
	{
		++scnt;
		while(s[top]!=u)scc[s[top]]=scnt,ins[s[top--]]=0;
		scc[s[top]]=scnt,ins[s[top--]]=0;
	}
}
ll all;
int main()
{
	ll n=read(),Xor=read(),And=read(),Or=read();
	all=(1<<(n+1))-1;
	for(ll s=0;s<=all;++s)
	{
		if((And&s)==And)
			for(ll t=all^s;;t=(t-1)&(all^s))
			{
				ll p=And|t;
				g[p].push_back(s^Xor);
				g[s].push_back(p^Xor);
				if(!t)break;
			}
		if((Or&s)==s)
			for(ll t=s;;t=(t-1)&s)
			{
				ll p=(Or^s)|t;
				g[p].push_back(s^Xor);
				g[s].push_back(p^Xor);
				if(!t)break;
			}
	}
	for(ll s=0;s<=all;++s)
		if(!dfn[s])tarjan(s);
	ll c=0;
	std::vector<ll>ans;
	for(ll s=0;s<=all;++s)
	{
		if(scc[s]==scc[s^Xor])return puts("No"),0;
		else if(c<(1<<n)&&scc[s]<scc[s^Xor])ans.push_back(s),++c;
	}
		
	puts("Yes");
	for(ll i=0;i<ans.size();++i)
	{
		if(i)putchar(' ');
		printf("%d",ans[i]);
	}
	puts("");
	return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 143544
final_rank: 6

code_snippet: #include<iostream>
#include<cstdio>
#include<cstring>
#define N (1<<14)+5
#define M 1<<23
using namespace std;
int dfn[N<<1],low[N<<1],in[N<<1];
int stack[N<<1],top,cnt;
int nxt[M],to[M],head[M];
int s[N<<1],num,n;
void add(int u,int v)
{
	++u,++v;
	nxt[++cnt]=head[u];
	to[cnt]=v;
	head[u]=cnt;
}
void tarjan(int now)
{
	dfn[now]=low[now]=++cnt;
	stack[top++]=now;
	in[now]=true;
	for(int i=head[now];i;i=nxt[i])
	{
		int v=to[i];
		if(!dfn[v])
		{
			tarjan(v);
			low[now]=min(low[v],low[now]);
		}
		else if(in[v])low[now]=min(dfn[v],low[now]);
	}
	if(low[now]==dfn[now])
	{
		int u;
		++num;
		do
		{
			u=stack[--top];
			in[u]=false;
			s[u]=num;
		}
		while(u!=now);
	}
}
int wx,wa,wo;
bool can(void)
{
	for(int i=1;i<=n;i++)
	if(!dfn[i]) tarjan(i);
	for(int i=0;i<n;i++) s[i]=s[i+1];
	for(int i=0;i<n;i++) if(s[i]==s[i^wx]) return false;
	return true;
}
int ans[N],tot;
int main()
{
	scanf("%d%d%d%d",&n,&wx,&wa,&wo);
	if(!wx){puts("No");return 0;}
	int m=1<<(n+1);
	for(int s=0;s<m;s++)
	{
		if((s&wa)==wa)
		{
			int s0=(m-1)&(~s);
			for(int t=s0;;t=(t-1)&s0)
			{
				int u=wa|t;
				add(s,u^wx);
				add(u,s^wx);
				if(!t) break;
			}
		}
		if((s|wo)==wo)
		{
			for(int t=s;;t=(t-1)&s)
			{
				int u=(wo^s)|t;
				add(s,u^wx);
				add(u,s^wx);
				if(!t) break;
			}
		}
	}
	n=m;
	if(!can()) printf("No");
	else
	{
		puts("Yes");
		for(int i=0;i<m;i++)
		if(s[i]<s[i^wx]) ans[++tot]=i;
		for(int i=1;i<=tot;i++) printf("%d%s",ans[i],i==tot?"\n":" ");
	}
	return 0;
}
accuracy: 0.9516129032258065
time_ms: 10
memory_kb: 12788
final_rank: 14

code_snippet: #include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
#define clr(x) memset(x,0,sizeof x))
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define kill _z_kill
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outv(x) cerr<<#x" = "<<x<<"  "
#define outtag(x) cerr<<"--------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
	For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
#define User_Time ((double)clock()/CLOCKS_PER_SEC)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned uint;
typedef long double LD;
typedef vector <int> vi;
typedef pair <int,int> pii;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
//int Pow(int x,int y){
//	int ans=1;
//	for (;y;y>>=1,x=(LL)x*x%mod)
//		if (y&1)
//			ans=(LL)ans*x%mod;
//	return ans;
//}
//void Add(int &x,int y){
//	if ((x+=y)>=mod)
//		x-=mod;
//}
//void Del(int &x,int y){
//	if ((x-=y)<0)
//		x+=mod;
//}
//int Add(int x){
//	return x>=mod?x-mod:x;
//}
//int Del(int x){
//	return x<0?x+mod:x;
//}
//void ckmax(int &x,int y){
//	if (x<y)
//		x=y;
//}
//void ckmin(int &x,int y){
//	if (x>y)
//		x=y;
//}
const int N=34000;
int n,X,A,O,XX,AA,OO,s,bs;
vi e[N],e2[N];
int dfn[N],low[N],st[N],inst[N],top=0,Time=0,cnt=0,con[N];
int op[N],res[N];
void Tarjan(int x){
	dfn[x]=low[x]=++Time;
	st[++top]=x,inst[x]=1;
	for (auto y : e[x])
		if (!dfn[y]){
			Tarjan(y);
			low[x]=min(low[x],low[y]);
		}
		else if (inst[y])
			low[x]=min(low[x],low[y]);
	if (dfn[x]==low[x]){
		++cnt;
		con[st[top]]=cnt;
		inst[st[top]]=0;
		while (st[top--]!=x){
			con[st[top]]=cnt;
			inst[st[top]]=0;
		}
	}
}
int in[N];
int main(){
	n=read(),X=XX=read(),A=AA=read(),O=OO=read();
	if (!X)
		return puts("No"),0;
	s=1<<(n+1);
	bs=s-1;
	For(i,0,s-1){
		int j=i^X;
		e[i].pb(j+s),e[j+s].pb(i);
		e[i+s].pb(j),e[j].pb(i+s);
	}
	{
		A^=bs;
		for (int x=A;~x;x=x==0?-1:(x-1)&A){
			for (int y=x;~y;y=y==0?-1:(y-1)&x){
				int i=x,j=y|(A^x);
				i^=bs,j^=bs;
//				assert((i&j)==AA);
				e[i].pb(j+s),e[j].pb(i+s);
			}
		}
	}
	{
		A=O;
		for (int x=A;~x;x=x==0?-1:(x-1)&A){
			for (int y=x;~y;y=y==0?-1:(y-1)&x){
				int i=x,j=y|(A^x);
				e[i].pb(j+s),e[j].pb(i+s);
			}
		}
	}
	For(i,0,s+s-1)
		if (!dfn[i])
			Tarjan(i);
	For(i,0,s-1){
		if (con[i]==con[i+s])
			return puts("No"),0;
		op[con[i]]=con[i+s];
		op[con[i+s]]=con[i];
	}
	For(i,0,s+s-1)
		for (auto j : e[i])
			if (con[i]!=con[j])
				e2[con[j]].pb(con[i]);
	For(i,1,cnt){
		if (res[i])
			continue;
		res[i]=1,res[op[i]]=-1;
	}
	puts("Yes");
	vi v;
	For(i,0,s-1)
		if (res[con[i]]==1)
			v.pb(i);
	assert((int)v.size()==s/2);
	for (auto i : v)
		printf("%d%c",i," \n"[i==v.back()]);
//	for (auto i : v)
//		for (auto j : v){
//			assert((i^j)!=XX);
//			assert((i&j)!=AA);
//			assert((i|j)!=OO);
//		}
	return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 138036
final_rank: 7

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 40005

struct GROUP{
	vector<int> nodes;
};

GROUP group[NUM]; //強連結成分のグループ
vector<int> G[NUM];
vector<int> reverse_G[NUM];
stack<int> S;

bool check[NUM];
int N,X,A,O;
int POW[16];
int table[NUM],in_num[NUM];
double sleep[NUM];

int group_index;

void dfs(int node_id){
	check[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		if(!check[G[node_id][i]])dfs(G[node_id][i]);
	}
	S.push(node_id);
}

void reverse_dfs(int node_id){
	check[node_id] = true;

	group[group_index].nodes.push_back(node_id); //group[group_index]にノードを突っ込む
	table[node_id] = group_index;

	for(int i = 0; i < reverse_G[node_id].size(); i++){
		if(!check[reverse_G[node_id][i]])reverse_dfs(reverse_G[node_id][i]);
	}
}


int main(){

	POW[0] = 1;
	for(int i = 1; i <= 15; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%d %d %d %d",&N,&X,&A,&O);
	if(X == 0){

		printf("No\n");
		return 0;
	}

	for(int i = 0; i < POW[N+1]; i++){
		for(int k = 0; k < POW[N+1]; k++){
			if(((i^k) == X) || ((i&k) == A) || ((i|k) == O)){ //true,falseを別にするペア

				G[i].push_back(k^X);
				reverse_G[k^X].push_back(i);
			}
		}
	}

	for(int i = 0; i < POW[N+1]; i++)check[i] = false;

	//まずは帰りがけ順を計算
	for(int i = 0; i < POW[N+1];i++){
		if(!check[i])dfs(i);
	}

	for(int i = 0; i < POW[N+1];i++)check[i] = false;

	group_index = -1;
	//ノードを、帰りがけ順の逆順に、各強連結成分(グループ)に分解
	while(!S.empty()){
		if(!check[S.top()]){
			group_index++;

			reverse_dfs(S.top());
		}
		S.pop();
	}

	for(int i = 0; i < POW[N+1]; i++){
		if(i < (i^X) && table[i] == table[i^X]){
			printf("No\n");
			return 0;
		}
	}

	vector<int> ANS;
	for(int i = 0; i < POW[N+1]; i++){
		if(i > (i^X))continue;

		if(table[i] > table[i^X]){

			ANS.push_back(i);
		}else{

			ANS.push_back(i^X);
		}
	}

	printf("Yes\n");
	printf("%d",ANS[0]);

	for(int i = 1; i < ANS.size(); i++){

		printf(" %d",ANS[i]);
	}
	printf("\n");

	return 0;
}
accuracy: 1
time_ms: 440
memory_kb: 136212
final_rank: 11

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 40005

struct GROUP{
	vector<int> nodes;
};

GROUP group[NUM]; //強連結成分のグループ
vector<int> G[NUM];
vector<int> reverse_G[NUM];
stack<int> S;

bool check[NUM];
int N,X,A,O;
int POW[16];
int table[NUM],in_num[NUM];
double sleep[NUM];

int group_index;

void dfs(int node_id){
	check[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		if(!check[G[node_id][i]])dfs(G[node_id][i]);
	}
	S.push(node_id);
}

void reverse_dfs(int node_id){
	check[node_id] = true;

	group[group_index].nodes.push_back(node_id); //group[group_index]にノードを突っ込む
	table[node_id] = group_index;

	for(int i = 0; i < reverse_G[node_id].size(); i++){
		if(!check[reverse_G[node_id][i]])reverse_dfs(reverse_G[node_id][i]);
	}
}


int main(){

	POW[0] = 1;
	for(int i = 1; i <= 15; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%d %d %d %d",&N,&X,&A,&O);
	if(X == 0){

		printf("No\n");
		return 0;
	}

	for(int i = 0; i < POW[N+1]; i++){
		for(int k = 0; k < POW[N+1]; k++){
			if(k == i)continue;
			if(((i^k) == X) || ((i&k) == A) || ((i|k) == O)){ //true,falseを別にするペア

				G[i].push_back(k^X);
				reverse_G[k^X].push_back(i);
			}
		}
	}

	for(int i = 0; i < POW[N+1]; i++)check[i] = false;

	//まずは帰りがけ順を計算
	for(int i = 0; i < POW[N+1];i++){
		if(!check[i])dfs(i);
	}

	for(int i = 0; i < POW[N+1];i++)check[i] = false;

	group_index = -1;
	//ノードを、帰りがけ順の逆順に、各強連結成分(グループ)に分解
	while(!S.empty()){
		if(!check[S.top()]){
			group_index++;

			reverse_dfs(S.top());
		}
		S.pop();
	}

	for(int i = 0; i < POW[N+1]; i++){
		if(i < (i^X) && table[i] == table[i^X]){
			printf("No\n");
			return 0;
		}
	}

	vector<int> ANS;
	for(int i = 0; i < POW[N+1]; i++){
		if(i > (i^X))continue;

		if(table[i] > table[i^X]){

			ANS.push_back(i);
		}else{

			ANS.push_back(i^X);
		}
	}

	printf("Yes\n");
	printf("%d",ANS[0]);

	for(int i = 1; i < ANS.size(); i++){

		printf(" %d",ANS[i]);
	}
	printf("\n");

	return 0;
}
accuracy: 0.11290322580645161
time_ms: 300
memory_kb: 8516
final_rank: 19

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 40005

struct GROUP{
	vector<int> nodes;
};

GROUP group[NUM]; //強連結成分のグループ
vector<int> G[NUM];
vector<int> reverse_G[NUM];
stack<int> S;

bool check[NUM];
int N,X,A,O;
int POW[16];
int table[NUM],in_num[NUM];
double sleep[NUM];

int group_index;

void dfs(int node_id){
	check[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		if(!check[G[node_id][i]])dfs(G[node_id][i]);
	}
	S.push(node_id);
}

void reverse_dfs(int node_id){
	check[node_id] = true;

	group[group_index].nodes.push_back(node_id); //group[group_index]にノードを突っ込む
	table[node_id] = group_index;

	for(int i = 0; i < reverse_G[node_id].size(); i++){
		if(!check[reverse_G[node_id][i]])reverse_dfs(reverse_G[node_id][i]);
	}
}


int main(){

	POW[0] = 1;
	for(int i = 1; i <= 15; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%d %d %d %d",&N,&X,&A,&O);
	if(X == 0){

		printf("No\n");
		return 0;
	}

	for(int i = 0; i < POW[N+1]; i++){
		for(int k = 0; k < POW[N+1]; k++){
			if(((i^k) == X) || ((i&k) == A) || ((i|k) == O)){ //true,falseを別にするペア

				G[i].push_back(k^X);
				reverse_G[k^X].push_back(i);

				G[k].push_back(i^X);
				reverse_G[i^X].push_back(k);
			}
		}
	}

	for(int i = 0; i < POW[N+1]; i++)check[i] = false;

	//まずは帰りがけ順を計算
	for(int i = 0; i < POW[N+1];i++){
		if(!check[i])dfs(i);
	}

	for(int i = 0; i < POW[N+1];i++)check[i] = false;

	group_index = -1;
	//ノードを、帰りがけ順の逆順に、各強連結成分(グループ)に分解
	while(!S.empty()){
		if(!check[S.top()]){
			group_index++;

			reverse_dfs(S.top());
		}
		S.pop();
	}

	for(int i = 0; i < POW[N+1]; i++){
		if(i < (i^X) && table[i] == table[i^X]){
			printf("No\n");
			return 0;
		}
	}

	vector<int> ANS;
	for(int i = 0; i < POW[N+1]; i++){
		if(i > (i^X))continue;

		if(table[i] > table[i^X]){

			ANS.push_back(i);
		}else{

			ANS.push_back(i^X);
		}
	}

	printf("Yes\n");
	printf("%d",ANS[0]);

	for(int i = 1; i < ANS.size(); i++){

		printf(" %d",ANS[i]);
	}
	printf("\n");

	return 0;
}
accuracy: 1
time_ms: 720
memory_kb: 255884
final_rank: 13

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 40005

struct GROUP{
	vector<int> nodes;
};

GROUP group[NUM]; //強連結成分のグループ
vector<int> G[NUM];
vector<int> reverse_G[NUM];
stack<int> S;

bool check[NUM];
int N,X,A,O;
int POW[16];
int table[NUM],in_num[NUM];
double sleep[NUM];

int group_index;

void dfs(int node_id){
	check[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		if(!check[G[node_id][i]])dfs(G[node_id][i]);
	}
	S.push(node_id);
}

void reverse_dfs(int node_id){
	check[node_id] = true;

	group[group_index].nodes.push_back(node_id); //group[group_index]にノードを突っ込む
	table[node_id] = group_index;

	for(int i = 0; i < reverse_G[node_id].size(); i++){
		if(!check[reverse_G[node_id][i]])reverse_dfs(reverse_G[node_id][i]);
	}
}


int main(){

	POW[0] = 1;
	for(int i = 1; i <= 15; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%d %d %d %d",&N,&X,&A,&O);
	if(X == 0){

		printf("No\n");
		return 0;
	}

	for(int i = 0; i < POW[N+1]; i++){
		for(int k = i+1; k < POW[N+1]; k++){
			if(((i^k) == X) || ((i&k) == A) || ((i|k) == O)){ //true,falseを別にするペア

				G[i].push_back(k^X);
				reverse_G[k^X].push_back(i);

				G[k].push_back(i^X);
				reverse_G[i^X].push_back(k);
			}
		}
	}

	for(int i = 0; i < POW[N+1]; i++)check[i] = false;

	//まずは帰りがけ順を計算
	for(int i = 0; i < POW[N+1];i++){
		if(!check[i])dfs(i);
	}

	for(int i = 0; i < POW[N+1];i++)check[i] = false;

	group_index = -1;
	//ノードを、帰りがけ順の逆順に、各強連結成分(グループ)に分解
	while(!S.empty()){
		if(!check[S.top()]){
			group_index++;

			reverse_dfs(S.top());
		}
		S.pop();
	}

	for(int i = 0; i < POW[N+1]; i++){
		if(i < (i^X) && table[i] == table[i^X]){
			printf("No\n");
			return 0;
		}
	}

	vector<int> ANS;
	for(int i = 0; i < POW[N+1]; i++){
		if(i > (i^X))continue;

		if(table[i] > table[i^X]){

			ANS.push_back(i);
		}else{

			ANS.push_back(i^X);
		}
	}

	printf("Yes\n");
	printf("%d",ANS[0]);

	for(int i = 1; i < ANS.size(); i++){

		printf(" %d",ANS[i]);
	}
	printf("\n");

	return 0;
}
accuracy: 0.11290322580645161
time_ms: 200
memory_kb: 8512
final_rank: 17

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 40005

struct GROUP{
	vector<int> nodes;
};

GROUP group[NUM]; //強連結成分のグループ
vector<int> G[NUM];
vector<int> reverse_G[NUM];
stack<int> S;

bool check[NUM];
int N,X,A,O;
int POW[15];
int table[NUM],in_num[NUM];
double sleep[NUM];

int group_index;

void dfs(int node_id){
	check[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		if(!check[G[node_id][i]])dfs(G[node_id][i]);
	}
	S.push(node_id);
}

void reverse_dfs(int node_id){
	check[node_id] = true;

	group[group_index].nodes.push_back(node_id); //group[group_index]にノードを突っ込む
	table[node_id] = group_index;

	for(int i = 0; i < reverse_G[node_id].size(); i++){
		if(!check[reverse_G[node_id][i]])reverse_dfs(reverse_G[node_id][i]);
	}
}


int main(){

	POW[0] = 1;
	for(int i = 1; i <= 14; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%d %d %d %d",&N,&X,&A,&O);
	if(X == 0){

		printf("No\n");
		return 0;
	}

	for(int i = 0; i < POW[N+1]; i++){
		for(int k = i+1; k < POW[N+1]; k++){
			if(((i&k) == A) || ((i|k) == O)){ //true,falseを別にするペア

				G[i].push_back(k^X);
				reverse_G[k^X].push_back(i);

				G[k].push_back(i^X);
				reverse_G[i^X].push_back(k);
			}
		}
	}

	for(int i = 0; i < POW[N+1]; i++)check[i] = false;

	//まずは帰りがけ順を計算
	for(int i = 0; i < POW[N+1];i++){
		if(!check[i])dfs(i);
	}

	for(int i = 0; i < POW[N+1];i++)check[i] = false;

	group_index = -1;
	//ノードを、帰りがけ順の逆順に、各強連結成分(グループ)に分解
	while(!S.empty()){
		if(!check[S.top()]){
			group_index++;

			reverse_dfs(S.top());
		}
		S.pop();
	}

	for(int i = 0; i < POW[N+1]; i++){
		if(i < (i^X) && table[i] == table[i^X]){
			printf("No\n");
			return 0;
		}
	}

	vector<int> ANS;
	for(int i = 0; i < POW[N+1]; i++){
		if(i > (i^X))continue;

		if(table[i] > table[i^X]){

			ANS.push_back(i);
		}else{

			ANS.push_back(i^X);
		}
	}

	printf("Yes\n");
	printf("%d",ANS[0]);

	for(int i = 1; i < ANS.size(); i++){

		printf(" %d",ANS[i]);
	}
	printf("\n");

	return 0;
}
accuracy: 0.11290322580645161
time_ms: 200
memory_kb: 7256
final_rank: 16

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 40005

struct GROUP{
	vector<int> nodes;
};

GROUP group[NUM]; //強連結成分のグループ
vector<int> G[NUM];
vector<int> reverse_G[NUM];
stack<int> S;

bool check[NUM];
int N,X,A,O;
int POW[15];
int table[NUM],in_num[NUM];
double sleep[NUM];

int group_index;

void dfs(int node_id){
	check[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		if(!check[G[node_id][i]])dfs(G[node_id][i]);
	}
	S.push(node_id);
}

void reverse_dfs(int node_id){
	check[node_id] = true;

	group[group_index].nodes.push_back(node_id); //group[group_index]にノードを突っ込む
	table[node_id] = group_index;

	for(int i = 0; i < reverse_G[node_id].size(); i++){
		if(!check[reverse_G[node_id][i]])reverse_dfs(reverse_G[node_id][i]);
	}
}


int main(){

	POW[0] = 1;
	for(int i = 1; i <= 14; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%d %d %d %d",&N,&X,&A,&O);
	if(X == 0){

		printf("No\n");
		return 0;
	}

	for(int i = 0; i < POW[N+1]; i++){
		for(int k = 0; k < POW[N+1]; k++){
			if(k == i)continue;
			if(((i^k) == X) || ((i&k) == A) || ((i|k) == O)){ //true,falseを別にするペア

				G[i].push_back(k^X);
				reverse_G[k^X].push_back(i);
			}
		}
	}

	for(int i = 0; i < POW[N+1]; i++)check[i] = false;

	//まずは帰りがけ順を計算
	for(int i = 0; i < POW[N+1];i++){
		if(!check[i])dfs(i);
	}

	for(int i = 0; i < POW[N+1];i++)check[i] = false;

	group_index = -1;
	//ノードを、帰りがけ順の逆順に、各強連結成分(グループ)に分解
	while(!S.empty()){
		if(!check[S.top()]){
			group_index++;

			reverse_dfs(S.top());
		}
		S.pop();
	}

	for(int i = 0; i < POW[N+1]; i++){
		if(i < (i^X) && table[i] == table[i^X]){
			printf("No\n");
			return 0;
		}
	}

	vector<int> ANS;
	for(int i = 0; i < POW[N+1]; i++){
		if(i > (i^X))continue;

		if(table[i] > table[i^X]){

			ANS.push_back(i);
		}else{

			ANS.push_back(i^X);
		}
	}

	printf("Yes\n");
	printf("%d",ANS[0]);

	for(int i = 1; i < ANS.size(); i++){

		printf(" %d",ANS[i]);
	}
	printf("\n");

	return 0;
}
accuracy: 0.11290322580645161
time_ms: 300
memory_kb: 8676
final_rank: 20

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 40005

struct GROUP{
	vector<int> nodes;
};

GROUP group[NUM]; //強連結成分のグループ
vector<int> G[NUM];
vector<int> reverse_G[NUM];
stack<int> S;

bool check[NUM];
int N,X,A,O;
int POW[15];
int table[NUM],in_num[NUM];
double sleep[NUM];

int group_index;

void dfs(int node_id){
	check[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		if(!check[G[node_id][i]])dfs(G[node_id][i]);
	}
	S.push(node_id);
}

void reverse_dfs(int node_id){
	check[node_id] = true;

	group[group_index].nodes.push_back(node_id); //group[group_index]にノードを突っ込む
	table[node_id] = group_index;

	for(int i = 0; i < reverse_G[node_id].size(); i++){
		if(!check[reverse_G[node_id][i]])reverse_dfs(reverse_G[node_id][i]);
	}
}


int main(){

	POW[0] = 1;
	for(int i = 1; i <= 14; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%d %d %d %d",&N,&X,&A,&O);
	if(X == 0){

		printf("No\n");
		return 0;
	}

	for(int i = 0; i < POW[N+1]; i++){
		for(int k = i+1; k < POW[N+1]; k++){
			if(((i^k) == X) || ((i&k) == A) || ((i|k) == O)){ //true,falseを別にするペア

				G[i].push_back(k^X);
				reverse_G[k^X].push_back(i);

				G[k].push_back(i^X);
				reverse_G[i^X].push_back(k);
			}
		}
	}

	for(int i = 0; i < POW[N+1]; i++)check[i] = false;

	//まずは帰りがけ順を計算
	for(int i = 0; i < POW[N+1];i++){
		if(!check[i])dfs(i);
	}

	for(int i = 0; i < POW[N+1];i++)check[i] = false;

	group_index = -1;
	//ノードを、帰りがけ順の逆順に、各強連結成分(グループ)に分解
	while(!S.empty()){
		if(!check[S.top()]){
			group_index++;

			reverse_dfs(S.top());
		}
		S.pop();
	}

	for(int i = 0; i < POW[N+1]; i++){
		if(i < (i^X) && table[i] == table[i^X]){
			printf("No\n");
			return 0;
		}
	}

	vector<int> ANS;
	for(int i = 0; i < POW[N+1]; i++){
		if(i > (i^X))continue;

		if(table[i] > table[i^X]){

			ANS.push_back(i);
		}else{

			ANS.push_back(i^X);
		}
	}

	printf("Yes\n");
	printf("%d",ANS[0]);

	for(int i = 1; i < ANS.size(); i++){

		printf(" %d",ANS[i]);
	}
	printf("\n");

	return 0;
}
accuracy: 0.11290322580645161
time_ms: 200
memory_kb: 8560
final_rank: 18

code_snippet: #include<bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,a,b,c,tot,ncnt,scnt;
int dfn[20000],low[20000],v[10000005],nxt[10000005],h[20000],col[20000];
bool ins[20000];
stack<int> s;

void addedge(int x,int y){v[++tot]=y; nxt[tot]=h[x]; h[x]=tot;}

void tarjan(int u){
	dfn[u]=low[u]=++ncnt;
	s.push(u); ins[u]=1;
	for(int p=h[u];p;p=nxt[p]){
		if(!dfn[v[p]]) tarjan(v[p]),chkmin(low[u],low[v[p]]);
		else if(ins[v[p]]) chkmin(low[u],dfn[v[p]]);
	}
	if(dfn[u]==low[u]){
		int tmp;
		scnt++;
		do{
			tmp=s.top(); s.pop();
			col[tmp]=scnt,ins[tmp]=0;	
		}while(tmp!=u);
	}
}

int main(){
	n=readint(); a=readint(); b=readint(); c=readint();
	if(a==0) return printf("No\n"),0;
	for(int i=0;i<(1<<(n+1));i++){
		if(((i&b)==b)||((i&c)==i))
			for(int j=i;j<(1<<(n+1));j++)
				if(((i&j)==b)||((i|j)==c))
					addedge(i,j^a),addedge(j,i^a);
	}
	for(int i=0;i<(1<<(n+1));i++) if(!dfn[i]) tarjan(i);
	for(int i=0;i<(1<<(n+1));i++) if(col[i]==col[i^a]) return printf("No\n"),0;
	printf("Yes\n");
	int num=0;
	for(int i=0;i<(1<<(n+1));i++){
		if(col[i]<col[i^a]){
			printf("%d",i);
			num++;
			if(num!=(1<<n)) printf(" ");
		}
	}
	printf("\n");
	return 0;
}
accuracy: 1
time_ms: 300
memory_kb: 78300
final_rank: 4