Language: C

#include <bits/stdc++.h>

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int LOG = 64;
const int N = 501;

ull g[N][N];
ull s[N], t[N], u[N], v[N];

int n;

void NO(){
  cout << "-1\n";
  exit(0);
}

bool red[N][N];
bool h1[N];
bool h2[N];
int n1[N];
int n2[N];
int c1[N];
int c2[N];

void solve(ll bit){
  for(int i = 0 ; i < n; i ++ ){
    for(int j = 0 ; j < n; j ++ ){
      red[i][j] = false;
    }
    n1[i]=-1;
    n2[i]=-1;
    c1[i] = 0;
    c2[i] = 0;
    h1[i]=h2[i]=false;
  }
  for(int i = 0 ; i < n; i ++ ){
    if((u[i] & bit)){
      if(s[i] == 0){
        h1[i]=true;
        for(int j = 0 ; j < n; j ++ ){
          red[i][j] = true;
          g[i][j] |= bit;
        }
      }
    }
    else{
      if(s[i] == 1){
        h1[i]=true;
        for(int j = 0 ; j < n; j ++ ){
          red[i][j] = true;
        }
      }
    }
  }
  for(int i = 0 ; i < n; i ++ ){
    if((v[i] & bit)){
      if(t[i] == 0){
        h2[i]=true;
        for(int j = 0 ; j < n; j ++ ){
       	  if(red[j][i] && (g[j][i] & bit == 0)){
          	cout << -1;
            exit(0);
          }
          red[j][i] = true;
          g[j][i] |= bit;
        }
      }
    }
    else{
      if(t[i] == 1){
        h2[i]=true;
        for(int j = 0 ; j < n; j ++ ){
          if(red[j][i] && (g[j][i] & bit)){
          	 cout << -1;
            exit(0);
          }
          red[j][i] = true;
        }
      }
    }
  }
  for(int i = 0 ; i < n; i ++ ){
    if((u[i]&bit)){
      if(s[i] == 1){
        for(int t = 0 ; t < n; t ++ ){
          if(red[i][t] && (g[i][t]&bit)) h1[i]=true;
        }
        if(!h1[i]) n1[i] = 1;
      }
    }
    else{
      if(s[i] == 0){
        for(int t = 0; t < n; t ++ ){
          if(red[i][t] && !(g[i][t]&bit)) h1[i]=true;
        }
        if(!h1[i]) n1[i] = 0;
      }
    }
    if((v[i]&bit)){
      if(t[i] == 1){
        for(int t = 0 ; t < n; t ++ ){
          if(red[t][i] && (g[t][i]&bit)) h2[i]=true;
        }
        if(!h2[i]) n2[i] = 1;
      }
    }
    else{
      if(t[i] == 0){
        for(int t = 0; t < n; t ++ ){
          if(red[t][i] && !(g[t][i]&bit)) h2[i]=true;
        }
        if(!h2[i]) n2[i] = 0;
      }
    }
  }
  for(int i = 0 ; i < n; i ++ ){
    if(!h1[i]){
      for(int j = 0 ; j < n; j ++ ){
        if(!red[i][j]) c1[i] ++ ;
      }
    }
    if(!h2[i]){
      for(int j = 0 ; j < n; j ++ ){
        if(!red[j][i]) c2[i] ++ ;
      }
    }
  }
  for(int i = 0 ; i < n; i ++ ){
    for(int j = 0 ; j < n; j ++ ){
      if(!red[i][j]){
        if(n1[i] == -1 && n2[j] == -1){
          continue;
        }
        if(n1[i] == -1){
          g[i][j] |= n2[j]*bit;
          n2[j]=-1;
          continue;
        }
        if(n2[j] == -1){
          g[i][j] |= n1[i]*bit;
          n1[i]=-1;
          continue;
        }
        if(n1[i] == n2[j]){
          g[i][j] |= n1[i] * bit;
          n1[i]=-1;
          n2[j]=-1;
          continue;
        }
        if(c1[i]<=c2[j]){
          g[i][j] |= n1[i]*bit;
          c2[j]--;
          n1[i]=-1;
        }
        else{
          g[i][j] |= n2[j]*bit;
          c1[i]--;
          n2[j]=-1;
        }
      }
    }
  }
  for(int i = 0 ; i < n; i ++ ){
    if(n1[i] != -1 || n2[i] != -1){
      cout << -1;
      exit(0);
    }
  }
}

int main(){
  fastIO;
  cin >> n;
  for(int i = 0; i < n; i ++ ){
    cin >> s[i];
  }
  for(int i = 0; i < n; i ++ ) 
    cin >> t[i];
  for(int i = 0; i < n; i ++ )
    cin >> u[i];
  for(int i = 0; i < n; i ++ ){
    cin >> v[i];
  }
  for(int i = LOG-1; i >= 0; i -- ) solve(1ll << i);
  for(int i = 0 ; i < n; i ++ ){
    for(int j = 0 ; j < n; j ++ ){
      cout << g[i][j] << " ";
    }
    cout << "\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.