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






Example

Input

2 6 1 5


Output

Yes
0 3 4 7

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

struct SCC {
    int N;
    vector<vector<int> > g, gr, g2i, t;
    vector<bool> visited;
    vector<int> i2g;
    stack<int> order;

    SCC(){}
    SCC(int n){init(n);}
    void init(int n){
        N = n;
        g.clear();
        g.resize(n);
        gr.clear();
        gr.resize(n);
        visited.resize(n);
        i2g.resize(n);
    }
    void add_edge(int u, int v) {
        g[u].emplace_back(v);
        gr[v].emplace_back(u);
    }

    void dfs(int x) {
        if (visited[x]) return;
        visited[x] = true;
        for (int i : g[x]) dfs(i);
        order.push(x);
    }

    void rdfs(int x, int k) {
        if (i2g[x] != -1) return;
        i2g[x] = k;
        for (int i : gr[x]) rdfs(i, k);
    }

    void build() {
        fill(visited.begin(), visited.end(), false);
        fill(i2g.begin(), i2g.end(), -1);
        for (int i = 0; i < N; i++) dfs(i);
        int p = 0;
        while (!order.empty()) {
            rdfs(order.top(), p++);
            order.pop();
        }
        g2i.clear();
        g2i.resize(p);
        for(int i=0;i<N;i++){
            g2i[i2g[i]].push_back(i);
        }
        t.resize(p);
        for(int i=0;i<N;i++){
            for (auto &to : g[i]) {
                int x = i2g[i], y = i2g[to];
                if (x == y) continue;
                t[x].push_back(y);
            }
        }
        for(int i=0;i<p;i++){
            sort(t[i].begin(), t[i].end());
            t[i].erase(unique(t[i].begin(), t[i].end()),t[i].end());
        }
    }
};

struct TwoSAT {
    int N;
    SCC scc;
    vector<int> ls;
    TwoSAT(){}
    TwoSAT(int n):N(n),scc(n*2){}
    int neg(int a){return (a+N)%(N*2);}
    void add_edge(int a, int b){
        scc.add_edge(a,b);
    }
    void add_if(int a, int b){
        // a -> b <=> !b -> !a
        add_edge(a,b);
        add_edge(neg(b),neg(a));
    }
    void add_iff(int a, int b){
        // (a <=> b) <=> a -> b and b -> a
        add_edge(a,b);
        add_edge(b,a);
    }
    void add_or(int a, int b){
        // a or b <=> !a -> b and !b -> a
        add_if(neg(a),b);
    }
    void add_nand(int a, int b){
        // a nand b <=> a -> !b and b -> !a
        add_if(a, neg(b));
    }
    void set_true(int a){
        // a <=> !a -> a
        add_edge(neg(a), a);
    }
    void set_false(int a){
        // !a <=> a -> !a
        add_edge(a, neg(a));
    }
    bool build(){
        scc.build();
        bool ok = true;
        for(int i=0;i<N;i++){
            ok &= scc.i2g[i] != scc.i2g[neg(i)];
        }
        if(ok){
            for(int i=0;i<N;i++){
                if(scc.i2g[i] > scc.i2g[neg(i)]){
                    ls.push_back(1);
                }
                else{
                    ls.push_back(0);
                }
            }
        }
        return ok;
    }
};

int main(){
    int N, X, A, O;
    cin >> N >> X >> A >> O;
    if(X == 0){
        cout << "No" << endl;
        return 0;
    }
    TwoSAT ts(1<<(N+1));
    for(int i=0;i<(1<<(N+1));i++){
        ts.add_nand(i,i^X);
        ts.add_or(i,i^X);
    }
    for(int i=0;i<(1<<(N+1));i++){
        if((i&A) == A){
            int j = i^((1<<(N+1))-1), k = j;
            while(1){
                ts.add_nand(i, k|A);
                if(k==0) break;
                k = (k-1)&j;
            }
        }
    }
    for(int i=0;i<(1<<(N+1));i++){
        if((i|O) == O){
            int j = i, k = j;
            while(1){
                ts.add_nand(i,k^((1<<(N+1))-1)&O);
                if(k==0) break;
                k = (k-1)&j;
            }
        }
    }
    if(ts.build()){
        cout << "Yes" << endl;
        vector<int> ans;
        for(int i=0;i<(1<<(N+1));i++){
            if(ts.ls[i]) ans.push_back(i);
        }
        for(int i=0;i<(1<<N);i++){
            cout << ans[i] << " \n"[i==(1<<N)-1];
        }
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}