#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define llint long long #define inf 1e18 #define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++) #define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) using namespace std; typedef pair P; llint n; llint s[505], t[505], u[505]; vector G[600005], revG[600005]; vector topo; bool used[600005]; int scc[600005], pos[600005]; int ans[505][505]; void tpsort(int v) { used[v] = true; for(int i = 0; i < G[v].size(); i++){ if(!used[G[v][i]]) tpsort(G[v][i]); } topo.push_back(v); } void sccdfs(int v, int id) { used[v] = true; scc[v] = id; for(int i = 0; i < revG[v].size(); i++){ if(!used[revG[v][i]]) sccdfs(revG[v][i], id); } } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 1; i <= n; i++) cin >> s[i]; for(int i = 1; i <= n; i++) cin >> t[i]; for(int i = 1; i <= n; i++) cin >> u[i]; llint N = (n+1)*n; for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ llint S = s[i]*n+j, T = j*n+t[i]; llint a = u[i]%2, b = u[i]/2; G[a*N+S].push_back((1-b)*N+T); G[b*N+T].push_back((1-a)*N+S); } } for(int i = 1; i <= 2*N; i++){ for(int j = 0; j < G[i].size(); j++){ llint u = G[i][j]; revG[u].push_back(i); } } for(int i = 1; i <= 2*N; i++) if(!used[i]) tpsort(i); reverse(topo.begin(), topo.end()); int id = 0; for(int i = 1; i <= 2*N; i++) used[i] = false; for(int i = 0; i < topo.size(); i++) if(!used[topo[i]]) sccdfs(topo[i], id++); for(int i = 0; i < topo.size(); i++) pos[topo[i]] = i; for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ int v = i*n+j; //cout << scc[v] << " " << scc[N+v] << endl; if(scc[v] == scc[N+v]){ cout << -1 << endl; return 0; } if(pos[v] < pos[N+v]) ans[i][j] = 1; else ans[i][j] = 0; } } for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ if(ans[s[i]][j]+ans[j][t[i]]*2 == u[i]){ cout << -1 << endl; return 0; } } } for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ cout << ans[i][j]; if(j < n) cout << " "; } cout << endl; } return 0; }