Language: C

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vl s(n), t(n), 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];
    vector<vl> must(n, vl(n));
    vector<vl> no(n, vl(n));
    rep(i, n) rep(j, n) {
        rep(k, 64) {
            if(s[i] == 0) {
                if(u[i]&(1LL<<k)) {
                    must[i][j] |= 1LL<<k;
                }
            }
            else {
                if(u[i]&(1LL<<k));
                else no[i][j] |= 1LL<<k;
            }

            if(t[j] == 0) {
                if(v[j]&(1LL<<k)) {
                    must[i][j] |= 1LL<<k;
                }
            }
            else {
                if(v[j]&(1LL<<k));
                else no[i][j] |= 1LL<<k;
            }
        }
    }
    rep(i, n) rep(j, n) if(must[i][j] & no[i][j]) {
        cout << -1 << '\n';
        return 0;
    }
    vector<vl> ans(n, vl(n));
    rep(i, n) rep(j, n) rep(k, 64) if(must[i][j] & (1LL<<k)) ans[i][j] |= (1LL<<k);
    rep(k, 64) {
        vi wa_i, wa_j, seki_i, seki_j;
        rep(i, n) rep(j, n) {
            if((s[i] == 0) ^ ((u[i]&(1LL<<k)))) {
                if(s[i] == 0) seki_i.pb(i);
                else wa_i.pb(i);
            }
            if((t[j] == 0) ^ ((v[j]&(1LL<<k)))) {
                if(t[j] == 0) seki_j.pb(j);
                else wa_j.pb(j);
            }
        }
        if(seki_i.size()> 0 && wa_i.empty() && wa_j.size() > 0 && seki_j.empty()) {
            if(min(seki_i.size(), wa_j.size()) == 1) {
                cout << -1 << '\n';
                return 0;
            }
            REP(wa_j_idx, 1, wa_j.size()) {
                ans[seki_i[0]][wa_j[wa_j_idx]] |= 1LL<<k;
            }
            {
                ans[seki_i[1]][wa_j[0]] |= 1LL<<k;
            }
        }
        else if(seki_j.size()> 0 && wa_j.empty() && wa_i.size() > 0 && seki_i.empty()) {
            if(min(seki_j.size(), wa_i.size()) == 1) {
                cout << -1 << '\n';
                return 0;
            }
            REP(wa_i_idx, 1, wa_i.size()) {
                ans[wa_i[wa_i_idx]][seki_j[0]] |= 1LL<<k;
            }
            {
                ans[wa_i[0]][seki_j[1]] |= 1LL<<k;
            }
        }
        else {
            for(auto&& i:wa_i) for(auto&& j : wa_j) ans[i][j] |= (1LL<<k);
        }
    }
    rep(i, n) rep(j, n) cout << (ans[i][j]) << (j+1 == n ? '\n': ' ');
    return 0;
}

Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.