Problem5330--ABC164——Task F:I hate Matrix Construction

5330: ABC164——Task F:I hate Matrix Construction

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 256 MiB

Description

Given are an integer NN and arrays SSTTUU, and VV, each of length NN. Construct an N×NN×N matrix aa that satisfy the following conditions:

  • ai,jai,j is an integer.
  • 0ai,j<2640≤ai,j<264.
  • If Si=0Si=0, the bitwise AND of the elements in the ii-th row is UiUi.
  • If Si=1Si=1, the bitwise OR of the elements in the ii-th row is UiUi.
  • If Ti=0Ti=0, the bitwise AND of the elements in the ii-th column is ViVi.
  • If Ti=1Ti=1, the bitwise OR of the elements in the ii-th column is ViVi.

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

Input

Input is given from Standard Input in the following format: 
N
S1 S2 ... SN
T1 T2 ... TN
U1 U2 ... UN
V1 V2 ... VN

Output

If there exists a matrix that satisfies the conditions, print one such matrix in the following format: 
a1,1 ... a1,N
.
.
.
aN,1 ... aN,N

Note that any matrix satisfying the conditions is accepted.

If no matrix satisfies the conditions, print 1−1.

Constraints

  • All values in input are integers.
  • 1N5001≤N≤500
  • 0Si10≤Si≤1
  • 0Ti10≤Ti≤1
  • 0Ui<2640≤Ui<264
  • 0Vi<264

Sample 1 Input

2
0 1
1 0
1 1
1 0

Sample 1 Output

1 1
1 0

In Sample Input 11, we need to find a matrix such that:

  • the bitwise AND of the elements in the 11-st row is 11;
  • the bitwise OR of the elements in the 22-nd row is 11;
  • the bitwise OR of the elements in the 11-st column is 11;
  • the bitwise AND of the elements in the 22-nd column is 00.

Sample 2 Input

2
1 1
1 0
15 15
15 11

Sample 2 Output

15 11
15 11

HINT

题目来源
AtCoder Beginner Contest 164,Task F。https://atcoder.jp/contests/abc164/tasks/abc164_f

Source/Category

AtCoder_ABC 100.164.ABC164