#include int ri() { int n; scanf("%d", &n); return n; } std::vector > hen; std::vector > rev; std::vector ord; std::vector visited; void dfs0(int i) { visited[i] = true; for (auto j : hen[i]) if (!visited[j]) dfs0(j); ord.push_back(i); } std::vector group; int group_cnt = 0; void dfs1(int i) { group[i] = group_cnt; for (auto j : rev[i]) if (group[j] == -1) dfs1(j); } int main() { int n = ri(); int a[n], b[n], c[n]; for (auto &i : a) i = ri() - 1; for (auto &i : b) i = ri() - 1; for (auto &i : c) i = ri(); hen.resize(n * n * 2); rev.resize(n * n * 2); #define INDEX(i, j, k) (((i) * n + (j)) * 2 + k) for (int i = 0; i < n; i++) { bool r0 = c[i] & 1; bool r1 = c[i] >> 1; for (int j = 0; j < n; j++) { hen[INDEX(a[i], j, r0)].push_back(INDEX(j, b[i], !r1)); rev[INDEX(j, b[i], !r1)].push_back(INDEX(a[i], j, r0)); hen[INDEX(j, b[i], r1)].push_back(INDEX(a[i], j, !r0)); rev[INDEX(a[i], j, !r0)].push_back(INDEX(j, b[i], r1)); } } visited.resize(n * n * 2); for (int i = 0; i < n * n * 2; i++) if (!visited[i]) dfs0(i); std::reverse(ord.begin(), ord.end()); group.resize(n * n * 2, -1); for (auto i : ord) if (group[i] == -1) { dfs1(i); group_cnt++; } bool possible = true; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (group[INDEX(i, j, 0)] == group[INDEX(i, j, 1)]) possible = false; if (!possible) puts("-1"); else { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++){ if (j) printf(" "); printf("%d", group[INDEX(i, j, 0)] < group[INDEX(i, j, 1)]); } puts(""); } } return 0; }