Problem: Given are an integer N and arrays S, T, U, and V, each of length N. Construct an N×N matrix a that satisfy the following conditions:

* a_{i,j} is an integer.
* 0 \leq a_{i,j} \lt 2^{64}.
* If S_{i} = 0, the bitwise AND of the elements in the i-th row is U_{i}.
* If S_{i} = 1, the bitwise OR of the elements in the i-th row is U_{i}.
* If T_{i} = 0, the bitwise AND of the elements in the i-th column is V_{i}.
* If T_{i} = 1, the bitwise OR of the elements in the i-th column is V_{i}.



However, there may be cases where no matrix satisfies the conditions.

Constraints

* All values in input are integers.
* 1 \leq N \leq 500
* 0 \leq S_{i} \leq 1
* 0 \leq T_{i} \leq 1
* 0 \leq U_{i} \lt 2^{64}
* 0 \leq V_{i} \lt 2^{64}

Input

Input is given from Standard Input in the following format:


N
S_{1} S_{2} ...  S_{N}
T_{1} T_{2} ...  T_{N}
U_{1} U_{2} ...  U_{N}
V_{1} V_{2} ...  V_{N}


Output

If there exists a matrix that satisfies the conditions, print one such matrix in the following format:


a_{1,1} ...  a_{1,N}
:
a_{N,1} ...  a_{N,N}


Note that any matrix satisfying the conditions is accepted.

If no matrix satisfies the conditions, print -1.

Examples

Input

2
0 1
1 0
1 1
1 0


Output

1 1
1 0


Input

2
1 1
1 0
15 15
15 11


Output

15 11
15 11

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using ull = unsigned long long;
using vi = vector<int>;

const vector<vi> NG(1,vi(1,-1));
const int B = 64;

int main(){
    int n;
    cin >>n;

    vector<int> s(n),t(n);
    vector<ull> u(n),v(n);
    rep(i,n) cin >>s[i];
    rep(i,n) cin >>t[i];
    rep(i,n) cin >>u[i];
    rep(i,n) cin >>v[i];

    auto calc = [&](const vi &row, const vi &col){
        vector<vi> r(n, vi(n,-1));

        vector<int> fr,fc;
        // row
        rep(i,n){
            int ALL = -1;
            if((s[i]^row[i])==1) ALL = row[i];

            if(ALL == -1) fr.pb(i);
            else rep(j,n) r[i][j] = ALL;
        }
        // col
        rep(i,n){
            int ALL = -1;
            if((t[i]^col[i])==1) ALL = col[i];

            if(ALL == -1) fc.pb(i);
            else{
                rep(j,n){
                    if(r[j][i]!=-1 && r[j][i]!=ALL) return NG;
                    r[j][i] = ALL;
                }
            }
        }

        int R = fr.size(), C = fc.size();
        if(R>=2 && C>=2){
            rep(i,R)rep(j,C) r[fr[i]][fc[j]] = (i+j)%2;
        }
        else if(R == 1){
            int ri = fr[0];
            for(int i:fc){
                vector<int> ct(2);
                rep(j,n)if(r[j][i] != -1) ++ct[r[j][i]];

                int v = s[ri];
                if(ct[col[i]]==0) v = col[i];
                r[ri][i] = v;
            }
        }
        else if(C == 1){
            int ci = fc[0];
            for(int i:fr){
                vector<int> ct(2);
                rep(j,n)if(r[i][j] != -1) ++ct[r[i][j]];

                int v = t[ci];
                if(ct[row[i]]==0) v = row[i];
                r[i][ci] = v;
            }
        }

        // check
        rep(i,n){
            if(s[i]==0){
                int val = 1;
                rep(j,n) val &= r[i][j];
                if(val != row[i]) return NG;
            }
            else{
                int val = 0;
                rep(j,n) val |= r[i][j];
                if(val != row[i]) return NG;
            }
        }
        rep(i,n){
            if(t[i]==0){
                int val = 1;
                rep(j,n) val &= r[j][i];
                if(val != col[i]) return NG;
            }
            else{
                int val = 0;
                rep(j,n) val |= r[j][i];
                if(val != col[i]) return NG;
            }
        }

        return r;
    };

    vector<vector<ull>> a(n, vector<ull>(n));
    rep(b,B){
        vi row(n), col(n);
        rep(i,n) row[i] = u[i]>>b&1;
        rep(i,n) col[i] = v[i]>>b&1;

        vector<vi> m = calc(row,col);
        if(m == NG){
            cout << -1 << "\n";
            return 0;
        }

        rep(i,n)rep(j,n)if(m[i][j]) a[i][j] |= (1ULL<<b);
    }

    rep(i,n)rep(j,n) cout << a[i][j] << " \n"[j==n-1];
    return 0;
}