#include using namespace std; #define DEBUG(x) cerr<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair template pair operator+(const pair &s, const pair &t) { return pair(s.first + t.first, s.second + t.second); } template pair operator-(const pair &s, const pair &t) { return pair(s.first - t.first, s.second - t.second); } template ostream& operator<<(ostream& os, pair p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout<; vector>>> out(N, vector>>(N, vector>(2))); vector visited; bool dfs(int y, int x, int val) { visited.push_back(pii(y, x)); ans[y][x] = val; for (P np: out[y][x][val]) { int ny = np.first.first, nx = np.first.second, nval = np.second; if (ans[ny][nx] != -1) { if (ans[ny][nx] == nval) return false; else continue; } if (not dfs(ny, nx, 1 - nval)) return false; } return true; } signed main() { fio(); int n; cin >> n; vi s(n), t(n), u(n); rep (i, n) { cin >> s[i]; s[i]--; } rep (i, n) { cin >> t[i]; t[i]--; } rep (i, n) cin >> u[i]; rep (i, n) { rep (j, n) { int y1 = s[i], x1 = j; int y2 = j, x2 = t[i]; int out1 = u[i] % 2; int out2 = u[i] / 2; out[y1][x1][out1].push_back(P(pii(y2, x2), out2)); out[y2][x2][out2].push_back(P(pii(y1, x1), out1)); // DEBUG(P(pii(y1, x1), out1)); } } rep (i, n) { rep (j, n) { if (ans[i][j] != -1) continue; visited.clear(); bool flag = false; rep (val, 2) { flag |= dfs(i, j, val); if (flag) break; else { rrep (i, visited.size()) { ans[visited[i].first][visited[i].second] = -1; visited.pop_back(); } } } if (not flag) { cout << -1 << endl; return 0; } } } rep (i, n) { rep (j, n) { cout << ans[i][j] << " "; } cout << endl; } }