Problem: Given are an integer N and arrays S, T, U, and V, each of length N. Construct an N×N matrix a that satisfy the following conditions:

* a_{i,j} is an integer.
* 0 \leq a_{i,j} \lt 2^{64}.
* If S_{i} = 0, the bitwise AND of the elements in the i-th row is U_{i}.
* If S_{i} = 1, the bitwise OR of the elements in the i-th row is U_{i}.
* If T_{i} = 0, the bitwise AND of the elements in the i-th column is V_{i}.
* If T_{i} = 1, the bitwise OR of the elements in the i-th column is V_{i}.



However, there may be cases where no matrix satisfies the conditions.

Constraints

* All values in input are integers.
* 1 \leq N \leq 500
* 0 \leq S_{i} \leq 1
* 0 \leq T_{i} \leq 1
* 0 \leq U_{i} \lt 2^{64}
* 0 \leq V_{i} \lt 2^{64}

Input

Input is given from Standard Input in the following format:


N
S_{1} S_{2} ...  S_{N}
T_{1} T_{2} ...  T_{N}
U_{1} U_{2} ...  U_{N}
V_{1} V_{2} ...  V_{N}


Output

If there exists a matrix that satisfies the conditions, print one such matrix in the following format:


a_{1,1} ...  a_{1,N}
:
a_{N,1} ...  a_{N,N}


Note that any matrix satisfying the conditions is accepted.

If no matrix satisfies the conditions, print -1.

Examples

Input

2
0 1
1 0
1 1
1 0


Output

1 1
1 0


Input

2
1 1
1 0
15 15
15 11


Output

15 11
15 11

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

#define ull unsigned long long

const int mxn = 505;
int n, s[mxn], t[mxn];
ull u[mxn], v[mxn], x[mxn][mxn];
int nw[mxn][mxn];
int vx[mxn], xsz, vy[mxn], ysz;

bool chk() {
	rep(i, n) if (s[i] == 0) { ull c = (ull)(-1); rep(j, n) c &= x[i][j]; if (c != u[i]) return 0; }
	rep(j, n) if (t[j] == 0) { ull c = (ull)(-1); rep(i, n) c &= x[i][j]; if (c != v[j]) return 0; }
	rep(i, n) if (s[i] == 1) { ull c = 0; rep(j, n) c |= x[i][j]; if (c != u[i]) return 0; }
	rep(j, n) if (t[j] == 1) { ull c = 0; rep(i, n) c |= x[i][j]; if (c != v[j]) return 0; }
	return 1;
}

int main() {
	scanf("%d", &n);
	rep(i, n) scanf("%d", &s[i]);
	rep(i, n) scanf("%d", &t[i]);
	rep(i, n) scanf("%llu", &u[i]);
	rep(i, n) scanf("%llu", &v[i]);
	rep(lv, 64) {
		xsz = ysz = 0;
		rep(i, n) {
			if (s[i] == 0 && (u[i] >> lv & 1) == 1) rep(j, n) nw[i][j] = 1; else
			if (s[i] == 1 && (u[i] >> lv & 1) == 0) rep(j, n) nw[i][j] = 0; else
			vx[xsz ++] = i;
		}
		rep(j, n) {
			if (t[j] == 0 && (v[j] >> lv & 1) == 1) rep(i, n) nw[i][j] = 1; else
			if (t[j] == 1 && (v[j] >> lv & 1) == 0) rep(i, n) nw[i][j] = 0; else
			vy[ysz ++] = j;
		}
		if (xsz == 0 || ysz == 0) {
		} else if (xsz == 1) {
			rep(j, ysz) {
				bool ok = 0;
				rep(i, n) if (i != vx[0] && nw[i][vy[j]] == (v[vy[j]] >> lv & 1)) { ok = 1; break; }
				if (ok) nw[vx[0]][vy[j]] = u[vx[0]] >> lv & 1; else nw[vx[0]][vy[j]] = v[vy[j]] >> lv & 1;
			}
		} else if (ysz == 1) {
			rep(i, xsz) {
				bool ok = 0;
				rep(j, n) if (j != vy[0] && nw[vx[i]][j] == (u[vx[i]] >> lv & 1)) { ok = 1; break; }
				if (ok) nw[vx[i]][vy[0]] = v[vy[0]] >> lv & 1; else nw[vx[i]][vy[0]] = u[vx[i]] >> lv & 1;
			}
		} else {
			rep(i, xsz) rep(j, ysz) nw[vx[i]][vy[j]] = (i + j) & 1;
		}
		rep(i, n) rep(j, n) x[i][j] |= (ull)(nw[i][j]) << lv;
	}
	if (!chk()) { puts("-1"); return 0; }
	rep(i, n) rep(j, n) printf("%llu%c", x[i][j], " \n"[j + 1 == n]);
	return 0;
}