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.

Submission attempts (in order):
import numpy as np

N = int(input())

S = np.array(list(map(int,input().split())),dtype = np.int64)
T = np.array(list(map(int,input().split())),dtype = np.int64)
U = np.array(list(map(int,input().split())),dtype = np.int64)
V = np.array(list(map(int,input().split())),dtype = np.int64)

ans = np.zeros((N,N),dtype = np.int64)
exit()
for n in range(64):
  u = (U>>n)&1
  v = (V>>n)&1
  invu = np.ones(N,int)-u
  invv = np.ones(N,int)-v
  b = np.zeros((N,N),int)
  check = np.zeros((N,N),int)
  
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),int)) & np.dot(np.array([v]).T,np.ones((1,N),int)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),int)) & np.dot(np.array([invv]).T,np.ones((1,N),int)).T
  b |= same1
  check |= (same1|same0)
  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: 
      flag = 0 
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
  
  
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: 
      flag = 0 
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  ans += b<<n


for item in ans:
  print(*list(item))

import numpy as np

N = int(input())

S = np.array(list(map(int,input().split())),dtype = np.uint64)
T = np.array(list(map(int,input().split())),dtype = np.uint64)
U = np.array(list(map(int,input().split())),dtype = np.uint64)
V = np.array(list(map(int,input().split())),dtype = np.uint64)

ans = np.zeros((N,N),dtype = np.uint64)

for n in range(64):
  u = (U>>n)&1
  v = (V>>n)&1
  invu = np.ones(N,dtype = np.uint64)-u
  invv = np.ones(N,dtype = np.uint64)-v
  b = np.zeros((N,N),dtype = np.uint64)
  check = np.zeros((N,N),dtype = np.uint64)
  
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([v]).T,np.ones((1,N),dtype = np.uint64)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([invv]).T,np.ones((1,N),dtype = np.uint64)).T
  b |= same1
  check |= (same1|same0)
  continue
  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: 
      flag = 0 
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
  
  
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: 
      flag = 0 
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  ans += b<<n


for item in ans:
  print(*list(item))


import numpy as np

N = int(input())

S = np.array(list(map(int,input().split())),dtype = np.uint64)
T = np.array(list(map(int,input().split())),dtype = np.uint64)
U = np.array(list(map(int,input().split())),dtype = np.uint64)
V = np.array(list(map(int,input().split())),dtype = np.uint64)

ans = np.zeros((N,N),dtype = np.uint64)

for n in range(64):
  u = (U>>n)&1
  v = (V>>n)&1
  invu = np.ones(N,dtype = np.uint64)-u
  invv = np.ones(N,dtype = np.uint64)-v
  b = np.zeros((N,N),dtype = np.uint64)
  check = np.zeros((N,N),dtype = np.uint64)
  
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([v]).T,np.ones((1,N),dtype = np.uint64)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([invv]).T,np.ones((1,N),dtype = np.uint64)).T
  b |= same1
  check |= (same1|same0)

  SUoneonelist = []
  for i in range(N):
    if S[i] == u[i] == 1:
      SUoneonelist.append(i)
  TVoneonelist = []
  for i in range(N):
    if T[i] == v[i] == 1:
      TVoneonelist.append(i)
  SUzerozerolist = []
  for i in range(N):
    if S[i] == u[i] == 0:
      SUzerozerolist.append(i)
  TVzerozerolist = []
  for i in range(N):
    if T[i] == v[i] == 0:
      TVzerozerolist.append(i)
  YOKOSUM = [sum(b[i]) for i in range(N)]
  TATESUM = [sum(b[:,i]) for i in range(N)]
  continue
  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: 
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  
  
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: 
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  ans += b<<n


for item in ans:
  print(*list(item))


import numpy as np

N = int(input())

S = list(map(int,input().split()))
T = list(map(int,input().split()))
U = np.array(list(map(int,input().split())),dtype = np.uint64)
V = np.array(list(map(int,input().split())),dtype = np.uint64)

ans = np.zeros((N,N),dtype = np.uint64)

for n in range(64):
  u = (U>>n)&1
  v = (V>>n)&1
  su = [int(S[i]*2+u[i]) for i in range(N)]
  tv = [int(T[i]*2+v[i]) for i in range(N)]
  suzerozero = []
  suoneone = []
  tvzerozero = []
  tvoneone = []
  for i in range(N):
    if su[i] == 0:
      suzerozero.append(i)
    if su[i] == 3:
      suoneone.append(i)
  for i in range(N):
    if tv[i] == 0:
      tvzerozero.append(i)
    if tv[i] == 3:
      tvoneone.append(i)
  
  b = np.zeros((N,N),dtype = np.uint64)
  
  for i in range(N):
    if su[i] == 1:
      b[i] = np.ones(N,int)
  
  for i in range(N):
    if tv[i] == 1:
      b[:,i] = np.ones(N,int)
  
  b |= np.dot(np.array([u]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([v]).T,np.ones((1,N),dtype = np.uint64)).T
  
  if 1 not in tv and 3 not in tv:
    m = len(tvzerozero)
    now = 0
    for i in suoneone:
      b[i][tvzerozero[now%m]] += 1
      now += 1
  
  if 1 not in su and 3 not in su:
    m = len(suzerozero)
    now = 0
    for i in tvoneone:
      b[suzerozero[now%m]][i] += 1
      now += 1
  ans += b<<n
print(ans)
def end():
  print(-1)
  exit()
for i in range(N):
  if S[i] == 0:
    now = ans[i][0]
    for j in range(1,N):
      now &= ans[i][j]
  if S[i] == 1:
    now = ans[i][0]
    for j in range(1,N):
      now |= ans[i][j]
  if now != U[i]:
    end()
for i in range(N):
  if T[i] == 0:
    now = ans[0][i]
    for j in range(1,N):
      now &= ans[j][i]
  if T[i] == 1:
    now = ans[0][i]
    for j in range(1,N):
      now |= ans[j][i]
  if now != V[i]:
    end()

for item in ans:
  print(*list(item))


import numpy as np

N = int(input())

S = np.array(list(map(int,input().split())),dtype = np.uint64)
T = np.array(list(map(int,input().split())),dtype = np.uint64)
U = np.array(list(map(int,input().split())),dtype = np.uint64)
V = np.array(list(map(int,input().split())),dtype = np.uint64)

ans = np.zeros((N,N),dtype = np.uint64)

for n in range(64):
  c = 0
  for i in range(N):
    for j in range(N):
      c += 1
  continue
  
  u = (U>>n)&1
  v = (V>>n)&1
  invu = np.ones(N,dtype = np.uint64)-u
  invv = np.ones(N,dtype = np.uint64)-v
  b = np.zeros((N,N),dtype = np.uint64)
  check = np.zeros((N,N),dtype = np.uint64)
  
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([v]).T,np.ones((1,N),dtype = np.uint64)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([invv]).T,np.ones((1,N),dtype = np.uint64)).T
  b |= same1
  check |= (same1|same0)

  SUoneonelist = []
  for i in range(N):
    if S[i] == u[i] == 1:
      SUoneonelist.append(i)
  TVoneonelist = []
  for i in range(N):
    if T[i] == v[i] == 1:
      TVoneonelist.append(i)
  SUzerozerolist = []
  for i in range(N):
    if S[i] == u[i] == 0:
      SUzerozerolist.append(i)
  TVzerozerolist = []
  for i in range(N):
    if T[i] == v[i] == 0:
      TVzerozerolist.append(i)
  YOKOSUM = [sum(b[i]) for i in range(N)]
  TATESUM = [sum(b[:,i]) for i in range(N)]
  continue
  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: 
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  
  
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: 
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  ans += b<<n


for item in ans:
  print(*list(item))


import numpy as np

N = int(input())

S = np.array(list(map(int,input().split())),dtype = np.uint64)
T = np.array(list(map(int,input().split())),dtype = np.uint64)
U = np.array(list(map(int,input().split())),dtype = np.uint64)
V = np.array(list(map(int,input().split())),dtype = np.uint64)

ans = np.zeros((N,N),dtype = np.uint64)

for n in range(64):
  u = (U>>n)&1
  v = (V>>n)&1
  invu = np.ones(N,dtype = np.uint64)-u
  invv = np.ones(N,dtype = np.uint64)-v
  b = np.zeros((N,N),dtype = np.uint64)
  check = np.zeros((N,N),dtype = np.uint64)
  
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([v]).T,np.ones((1,N),dtype = np.uint64)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([invv]).T,np.ones((1,N),dtype = np.uint64)).T
  b |= same1
  check |= (same1|same0)
  continue
  SUoneonelist = []
  for i in range(N):
    if S[i] == u[i] == 0:
      SUoneonelist.append(i)
  TVoneonelist = []
  for i in range(N):
    if T[i] == v[i] == 0:
      TVoneonelist.append(i)
  SUzerozerolist = []
  for i in range(N):
    if S[i] == u[i] == 0:
      SUzerozerolist.append(i)
  TVzerozerolist = []
  for i in range(N):
    if T[i] == v[i] == 0:
      TVzerozerolist.append(i)
  continue
  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: 
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  
  
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: 
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  ans += b<<n


for item in ans:
  print(*list(item))


import numpy as np

N = int(input())

S = np.array(list(map(int,input().split())),dtype = np.uint64)
T = np.array(list(map(int,input().split())),dtype = np.uint64)
U = np.array(list(map(int,input().split())),dtype = np.uint64)
V = np.array(list(map(int,input().split())),dtype = np.uint64)

ans = np.zeros((N,N),dtype = np.uint64)

for n in range(64):
  c = 0
  for i in range(N):
    for j in range(N):
      c += 1
      c += 1
  continue
  
  u = (U>>n)&1
  v = (V>>n)&1
  invu = np.ones(N,dtype = np.uint64)-u
  invv = np.ones(N,dtype = np.uint64)-v
  b = np.zeros((N,N),dtype = np.uint64)
  check = np.zeros((N,N),dtype = np.uint64)
  
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([v]).T,np.ones((1,N),dtype = np.uint64)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([invv]).T,np.ones((1,N),dtype = np.uint64)).T
  b |= same1
  check |= (same1|same0)

  SUoneonelist = []
  for i in range(N):
    if S[i] == u[i] == 1:
      SUoneonelist.append(i)
  TVoneonelist = []
  for i in range(N):
    if T[i] == v[i] == 1:
      TVoneonelist.append(i)
  SUzerozerolist = []
  for i in range(N):
    if S[i] == u[i] == 0:
      SUzerozerolist.append(i)
  TVzerozerolist = []
  for i in range(N):
    if T[i] == v[i] == 0:
      TVzerozerolist.append(i)
  YOKOSUM = [sum(b[i]) for i in range(N)]
  TATESUM = [sum(b[:,i]) for i in range(N)]
  continue
  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: 
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  
  
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: 
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  ans += b<<n


for item in ans:
  print(*list(item))


import numpy as np

N = int(input())

S = np.array(list(map(int,input().split())),dtype = np.uint64)
T = np.array(list(map(int,input().split())),dtype = np.uint64)
U = np.array(list(map(int,input().split())),dtype = np.uint64)
V = np.array(list(map(int,input().split())),dtype = np.uint64)

ans = np.zeros((N,N),dtype = np.uint64)

for n in range(64):
  u = (U>>n)&1
  v = (V>>n)&1
  invu = np.ones(N,dtype = np.uint64)-u
  invv = np.ones(N,dtype = np.uint64)-v
  b = np.zeros((N,N),dtype = np.uint64)
  check = np.zeros((N,N),dtype = np.uint64)
  
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([v]).T,np.ones((1,N),dtype = np.uint64)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([invv]).T,np.ones((1,N),dtype = np.uint64)).T
  b |= same1
  check |= (same1|same0)

  SUoneonelist = []
  for i in range(N):
    if S[i] == u[i] == 1:
      SUoneonelist.append(i)
  TVoneonelist = []
  for i in range(N):
    if T[i] == v[i] == 1:
      TVoneonelist.append(i)
  SUzerozerolist = []
  for i in range(N):
    if S[i] == u[i] == 0:
      SUzerozerolist.append(i)
  TVzerozerolist = []
  for i in range(N):
    if T[i] == v[i] == 0:
      TVzerozerolist.append(i)
  continue
  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: 
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  
  
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: 
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  ans += b<<n


for item in ans:
  print(*list(item))


import numpy as np

N = int(input())

S = np.array(list(map(int,input().split())),dtype = np.uint64)
T = np.array(list(map(int,input().split())),dtype = np.uint64)
U = np.array(list(map(int,input().split())),dtype = np.uint64)
V = np.array(list(map(int,input().split())),dtype = np.uint64)

ans = np.zeros((N,N),dtype = np.uint64)

for n in range(64):
  u = (U>>n)&1
  v = (V>>n)&1
  invu = np.ones(N,dtype = np.uint64)-u
  invv = np.ones(N,dtype = np.uint64)-v
  b = np.zeros((N,N),dtype = np.uint64)
  check = np.zeros((N,N),dtype = np.uint64)
  
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([v]).T,np.ones((1,N),dtype = np.uint64)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([invv]).T,np.ones((1,N),dtype = np.uint64)).T
  b |= same1
  check |= (same1|same0)
  
  SUoneonelist = []
  for i in range(N):
    if S[i] == u[i] == 0:
      SUoneonelist.append(i)
  TVoneonelist = []
  for i in range(N):
    if T[i] == v[i] == 0:
      TVoneonelist.append(i)
  SUzerozerolist = []
  for i in range(N):
    if S[i] == u[i] == 0:
      SUzerozerolist.append(i)
  TVoneonelist = []
  for i in range(N):
    if T[i] == v[i] == 0:
      TVzerozerolist.append(i)
  continue
  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: 
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  
  
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: 
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  ans += b<<n


for item in ans:
  print(*list(item))


import numpy as np

N = int(input())

S = np.array(list(map(int,input().split())),dtype = np.int64)
T = np.array(list(map(int,input().split())),dtype = np.int64)
U = np.array(list(map(int,input().split())),dtype = np.int64)
V = np.array(list(map(int,input().split())),dtype = np.int64)

ans = np.zeros((N,N),dtype = np.int64)

for n in range(64):
  u = (U>>n)&1
  v = (V>>n)&1
  invu = np.ones(N,int)-u
  invv = np.ones(N,int)-v
  b = np.zeros((N,N),int)
  check = np.zeros((N,N),int)
  
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  break
  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),int)) & np.dot(np.array([v]).T,np.ones((1,N),int)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),int)) & np.dot(np.array([invv]).T,np.ones((1,N),int)).T
  b |= same1
  check |= (same1|same0)
  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: 
      flag = 0 
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
  
  
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: 
      flag = 0 
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  ans += b<<n


for item in ans:
  print(*list(item))

import numpy as np

N = int(input())

S = list(map(int,input().split()))
T = list(map(int,input().split()))
U = np.array(list(map(int,input().split())),dtype = np.uint64)
V = np.array(list(map(int,input().split())),dtype = np.uint64)

ans = np.zeros((N,N),dtype = np.uint64)

for n in range(64):
  u = (U>>n)&1
  v = (V>>n)&1
  su = [int(S[i]*2+u[i]) for i in range(N)]
  tv = [int(T[i]*2+v[i]) for i in range(N)]
  suzerozero = []
  suoneone = []
  tvzerozero = []
  tvoneone = []
  for i in range(N):
    if su[i] == 0:
      suzerozero.append(i)
    if su[i] == 3:
      suoneone.append(i)
  for i in range(N):
    if tv[i] == 0:
      tvzerozero.append(i)
    if tv[i] == 3:
      tvoneone.append(i)
  
  b = np.zeros((N,N),dtype = np.uint64)
  
  for i in range(N):
    if su[i] == 1:
      b[i] = np.ones(N,int)
  
  for i in range(N):
    if tv[i] == 1:
      b[:,i] = np.ones(N,int)
  
  b |= np.dot(np.array([u]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([v]).T,np.ones((1,N),dtype = np.uint64)).T
  
  if 1 not in tv and 3 not in tv:
    m = len(tvzerozero)
    now = 0
    for i in suoneone:
      b[i][tvzerozero[now%m]] += 1
      now += 1
  
  if 1 not in su and 3 not in su:
    m = len(suzerozero)
    now = 0
    for i in tvoneone:
      b[suzerozero[now%m]][i] += 1
      now += 1
  ans += b<<n

def end():
  print(-1)
  exit()
for i in range(N):
  if S[i] == 0:
    now = ans[i][0]
    for j in range(1,N):
      now &= ans[i][j]
  if S[i] == 1:
    now = ans[i][0]
    for j in range(1,N):
      now |= ans[i][j]
  if now != U[i]:
    end()
for i in range(N):
  if T[i] == 0:
    now = ans[0][i]
    for j in range(1,N):
      now &= ans[j][i]
  if T[i] == 1:
    now = ans[0][i]
    for j in range(1,N):
      now |= ans[j][i]
  if now != V[i]:
    end()

for item in ans:
  print(*list(item))


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Accepted