#pragma GCC optimize ("Ofast") #include using namespace std; void *wmem; char memarr[96000000]; template inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(int x){ int s=0; int m=0; char f[10]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } template inline void arrInsert(const int k, int &sz, S a[], const S aval){ int i; sz++; for(i=sz-1;i>k;i--){ a[i] = a[i-1]; } a[k] = aval; } template inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval){ int i; sz++; for(i=sz-1;i>k;i--){ a[i] = a[i-1]; } for(i=sz-1;i>k;i--){ b[i] = b[i-1]; } a[k] = aval; b[k] = bval; } template inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval){ int i; sz++; for(i=sz-1;i>k;i--){ a[i] = a[i-1]; } for(i=sz-1;i>k;i--){ b[i] = b[i-1]; } for(i=sz-1;i>k;i--){ c[i] = c[i-1]; } a[k] = aval; b[k] = bval; c[k] = cval; } template inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval, V d[], const V dval){ int i; sz++; for(i=sz-1;i>k;i--){ a[i] = a[i-1]; } for(i=sz-1;i>k;i--){ b[i] = b[i-1]; } for(i=sz-1;i>k;i--){ c[i] = c[i-1]; } for(i=sz-1;i>k;i--){ d[i] = d[i-1]; } a[k] = aval; b[k] = bval; c[k] = cval; d[k] = dval; } struct graph{ int N; int *es; int **edge; void setEdge(int N__, int M, int A[], int B[], void **mem = &wmem){ int i; N = N__; walloc1d(&es, N, mem); walloc1d(&edge, N, mem); for(i=(0);i<(N);i++){ es[i] = 0; } for(i=(0);i<(M);i++){ es[A[i]]++; es[B[i]]++; } for(i=(0);i<(N);i++){ walloc1d(&edge[i], es[i], mem); } for(i=(0);i<(N);i++){ es[i] = 0; } for(i=(0);i<(M);i++){ edge[A[i]][es[A[i]]++] = B[i]; edge[B[i]][es[B[i]]++] = A[i]; } } int bipartite(int res[] = NULL, void *mem = wmem){ int i; int j; int k, s; int *st; int sts; if(res==NULL){ walloc1d(&res, N, &mem); } walloc1d(&st, N, &mem); for(i=(0);i<(N);i++){ res[i] = -1; } for(s=(0);s<(N);s++){ i = s; if(res[i]==-1){ res[i] = 0; sts = 0; st[sts++] = i; while(sts){ i = st[--sts]; for(j=(0);j<(es[i]);j++){ k = edge[i][j]; if(res[k]==-1){ res[k] = 1 - res[i]; st[sts++] = k; } if(res[i] + res[k] != 1){ return 0; } } } } } return 1; } } ; int N; int S[500]; int T[500]; int U[500]; int n; int m; int a[1000000]; int b[1000000]; int res[1000000]; graph g; int main(){ int i; wmem = memarr; int x; int y; int z; rd(N); { int Lj4PdHRW; for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){ rd(S[Lj4PdHRW]);S[Lj4PdHRW] += (-1); } } { int e98WHCEY; for(e98WHCEY=(0);e98WHCEY<(N);e98WHCEY++){ rd(T[e98WHCEY]);T[e98WHCEY] += (-1); } } { int FmcKpFmN; for(FmcKpFmN=(0);FmcKpFmN<(N);FmcKpFmN++){ rd(U[FmcKpFmN]); } } n = 2*N*N; for(i=(0);i<(N);i++){ int j; for(j=(0);j<(N);j++){ x = S[i] * N + j; y = j * N + T[i]; z = U[i]; if(z%2==0){ if(z/2==0){ arrInsert(m, m, a, x +0, b, y +0); } else{ arrInsert(m, m, a, x +0, b, y +N*N); } } else{ if(z/2==0){ arrInsert(m, m, a, x +N*N, b, y +0); } else{ arrInsert(m, m, a, x +N*N, b, y +N*N); } } if(z%2==0){ if(z/2==0){ arrInsert(m, m, a, x +0, b, y +0); } else{ arrInsert(m, m, a, x +0, b, y +N*N); } } else{ if(z/2==0){ arrInsert(m, m, a, x +N*N, b, y +0); } else{ arrInsert(m, m, a, x +N*N, b, y +N*N); } } } } for(i=(0);i<(N*N);i++){ arrInsert(m, m, a, i, b, i + N*N); } g.setEdge(n, m, a, b); if(!g.bipartite(res)){ wt_L(-1); wt_L('\n'); return 0; } for(i=(0);i<(N);i++){ { int ZIeRIny5; if(N==0){ wt_L('\n'); } else{ for(ZIeRIny5=(0);ZIeRIny5<(N-1);ZIeRIny5++){ wt_L((res+N*i)[ZIeRIny5]); wt_L(' '); } wt_L((res+N*i)[ZIeRIny5]); wt_L('\n'); } } } return 0; } // cLay varsion 20200509-1 // --- original code --- // int N, S[500], T[500], U[500]; // int n, m, a[1d6], b[1d6]; // int res[1d6]; // graph g; // { // int x, y, z; // rd(N,(S--)(N),(T--)(N),U(N)); // n = 2*N*N; // rep(i,N) rep(j,N){ // x = S[i] * N + j; // y = j * N + T[i]; // z = U[i]; // arrInsert(m, m, a, x + if[z%2==0, 0, N*N], b, y + if[z/2==0, 0, N*N]); // arrInsert(m, m, a, x + if[z%2==0, 0, N*N], b, y + if[z/2==0, 0, N*N]); // } // rep(i,N*N) arrInsert(m, m, a, i, b, i + N*N); // g.setEdge(n, m, a, b); // if(!g.bipartite(res)) wt(-1), return 0; // wt(res(n)); // rep(i,N) wt(((res+N*i))(N)); // }