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 FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef unsigned long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (506)
ll n;
ll S[MAXN], T[MAXN], U[MAXN], V[MAXN], UU[MAXN], VV[MAXN], ans[MAXN][MAXN];
bool grid[MAXN][MAXN];
bool or1[MAXN], and0[MAXN];
bool chk(ll j,string x){
	if(x=="and0") return T[j] == 0 && V[j] == 0;
	if(x=="and1") return T[j] == 0 && V[j] == 1;
	if(x=="or0") return T[j] == 1 && V[j] == 0;
	if(x=="or1") return T[j] == 1 && V[j] == 1;
	assert(0);
}
void solve(){
	bool ga1=0, go0=0;
	FOR(j,0,n-1) ga1 |= chk(j, "and1"), go0 |= chk(j, "or0"), or1[j] = chk(j, "or1"), and0[j] = chk(j, "and0");
	FOR(i,0,n-1) {
		if(S[i]==0&&U[i]==0) { // AND 0
			bool can = 0;
			FOR(j,0,n-1) if(!chk(j,"and1")) can=1;
			if(!can) {
				cout<<"-1\n";
				exit(0);
			}
			ll fix = -1;
			FOR(j,0,n-1) if(!or1[j] && !chk(j, "and1")) {
				fix = j;
			}
			if(fix == -1) FOR(j,0,n-1) if(or1[j]) fix=j;
			assert(~fix);
			FOR(j,0,n-1) if(j==fix || chk(j,"or0") || and0[j]) {
				if(and0[j]) and0[j]=0;
			}else{
				grid[i][j]=1;
				if(or1[j]) or1[j]=0;
			}
		}else if(S[i]==0&&U[i]==1){ // AND 1
			if(go0){
				cout<<"-1\n";
				exit(0);
			}
			FOR(j,0,n-1) grid[i][j]=1, or1[j]=0;
		}else if(S[i]==1&&U[i]==0) { // OR 0
			if(ga1){
				cout<<"-1\n";
				exit(0);
			}
			// all 0
			FOR(j,0,n-1) and0[j]=0;
		}else if(S[i]==1&&U[i]==1) { // OR 1
			bool can=0;
			FOR(j,0,n-1) if(!chk(j, "or0")) can=1;
			if(!can) {
				cout<<"-1\n";
				exit(0);
			}
			ll fix = -1;
			FOR(j,0,n-1) if(!and0[j] && !chk(j, "or0")) {
				fix = j;
			}
			if(fix == -1) FOR(j,0,n-1) if(and0[j]) fix=j;
			assert(~fix);
			FOR(j,0,n-1) if(j == fix || or1[j] || chk(j, "and1")) {
				if(or1[j]) or1[j]=0;
				grid[i][j]=1;
			}else {
				if(and0[j]) and0[j]=0;
			}
		} else exit(0);
	}
	FOR(j,0,n-1) if(and0[j] || or1[j]) {
		cout<<"-1\n";
		exit(0);
	}
}
int main(){
	FAST
	cin>>n;
	FOR(i,0,n-1) cin>>S[i]; FOR(i,0,n-1) cin>>T[i]; FOR(i,0,n-1) cin>>UU[i]; FOR(i,0,n-1) cin>>VV[i];
	FOR(i,0,63){
		mmst(grid,0), mmst(or1,0), mmst(and0,0);
		FOR(j,0,n-1) U[j] = ((1ll<<i)&UU[j]) ? 1 : 0;
		FOR(j,0,n-1) V[j] = ((1ll<<i)&VV[j]) ? 1 : 0;
		solve();
		FOR(j,0,n-1) FOR(k,0,n-1) if(grid[j][k]) ans[j][k]|=1ll<<i;
	}
	FOR(i,0,n-1) FOR(j,0,n-1) cout<<ans[i][j]<<" \n"[j==n-1];
}