import sys sys.setrecursionlimit(6666666) readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def StronglyConnectedComponents(N, G, RG): group_cnt = 0 used = [0] * N group = [0] * N order = list() def dfs(s): st = [s] while st: v = st[-1] if used[v] < len(G[v]): if not used[G[v][used[v]]]: st.append(G[v][used[v]]) used[v] += 1 else: order.append(v) st.pop() return def rdfs(s, col): group[s] = col used[s] = 1 for t in RG[s]: if not used[t]: rdfs(t, col) for v in range(N): if not used[v]: dfs(v) used = [0] * N for v in reversed(order): if not used[v]: rdfs(v, group_cnt) group_cnt += 1 return group_cnt, group class TwoSatisfilability: def __init__(self, N): self.N = N self.G = [list() for _ in range(N*2)] self.RG = [list() for _ in range(N*2)] self.res = [0] * N def solve(self): _, group = StronglyConnectedComponents(self.N * 2, self.G, self.RG) for i in range(self.N): if group[i] == group[i+self.N]: return False, list() self.res[i] = int(group[i] > group[i+self.N]) return True, self.res def _add_edge(self, a, b): self.G[a].append(b) self.RG[b].append(a) return def add(self, a, apos, b, bpos): ''' a V b ''' self._add_edge(a + self.N * apos, b + self.N * (bpos ^ 1)) self._add_edge(b + self.N * bpos, a + self.N * (apos ^ 1)) return def solve(): n = ni() s = [x-1 for x in nl()] t = [x-1 for x in nl()] u = nl() sat = TwoSatisfilability(n**2) for i in range(n): cs, ct, cu = s[i], t[i], u[i] for j in range(n): x = cs * n + j y = j * n + ct sat.add(x, (cu & 1) ^ 1, y, (cu >> 1) ^ 1) bo, ret = sat.solve() if not bo: print(-1) else: for i in range(n): print(*ret[i*n:(i+1)*n]) return solve()