Luckily, Serval got onto the right bus, and he came to the kindergarten on time. After coming to kindergarten, he found the toy bricks very funny.

He has a special interest to create difficult problems for others to solve. This time, with many $1 \times 1 \times 1$ toy bricks, he builds up a 3-dimensional object. We can describe this object with a $n \times m$ matrix, such that in each cell $(i,j)$, there are $h_{i,j}$ bricks standing on the top of each other.

However, Serval doesn't give you any $h_{i,j}$, and just give you the front view, left view, and the top view of this object, and he is now asking you to restore the object. Note that in the front view, there are $m$ columns, and in the $i$-th of them, the height is the maximum of $h_{1,i},h_{2,i},\dots,h_{n,i}$. It is similar for the left view, where there are $n$ columns. And in the top view, there is an $n \times m$ matrix $t_{i,j}$, where $t_{i,j}$ is $0$ or $1$. If $t_{i,j}$ equals $1$, that means $h_{i,j}>0$, otherwise, $h_{i,j}=0$.

However, Serval is very lonely because others are bored about his unsolvable problems before, and refused to solve this one, although this time he promises there will be at least one object satisfying all the views. As his best friend, can you have a try?


-----Input-----

The first line contains three positive space-separated integers $n, m, h$ ($1\leq n, m, h \leq 100$) — the length, width and height.

The second line contains $m$ non-negative space-separated integers $a_1,a_2,\dots,a_m$, where $a_i$ is the height in the $i$-th column from left to right of the front view ($0\leq a_i \leq h$).

The third line contains $n$ non-negative space-separated integers $b_1,b_2,\dots,b_n$ ($0\leq b_j \leq h$), where $b_j$ is the height in the $j$-th column from left to right of the left view.

Each of the following $n$ lines contains $m$ numbers, each is $0$ or $1$, representing the top view, where $j$-th number of $i$-th row is $1$ if $h_{i, j}>0$, and $0$ otherwise.

It is guaranteed that there is at least one structure satisfying the input.


-----Output-----

Output $n$ lines, each of them contains $m$ integers, the $j$-th number in the $i$-th line should be equal to the height in the corresponding position of the top view. If there are several objects satisfying the views, output any one of them.


-----Examples-----
Input
3 7 3
2 3 0 0 2 0 1
2 1 3
1 0 0 0 1 0 0
0 0 0 0 0 0 1
1 1 0 0 0 0 0

Output
1 0 0 0 2 0 0
0 0 0 0 0 0 1
2 3 0 0 0 0 0

Input
4 5 5
3 5 2 0 4
4 2 5 4
0 0 0 0 1
1 0 1 0 0
0 1 0 0 0
1 1 1 0 0

Output
0 0 0 0 4
1 0 2 0 0
0 5 0 0 0
3 4 1 0 0



-----Note-----

 [Image] 

The graph above illustrates the object in the first example.

 [Image] 

 [Image] 

The first graph illustrates the object in the example output for the second example, and the second graph shows the three-view drawing of it.

Difficulty: interview

Starter code:

Solutions:
def main():
    n, m, h = map(int, input().split())
    row = list(map(int, input().split()))
    col = list(map(int, input().split()))
    mat = [list(map(int, input().split())) for _ in range(n)]
    for i in range(n):
        for j in range(m):
            if mat[i][j]:
                mat[i][j] = min(col[i], row[j])
    for arr in mat: print(*arr)
    return 0
main()

n, m, h = map(int, input().split())
top = list(map(int, input().split()))
left = list(map(int, input().split()))

matrix = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
    for j in range(m):
        if matrix[i][j] == 1:
            print(min(left[i], top[j]), end=" ")
        else:
            print(0, end=" ")
    print()


# AC
import sys


class Main:
    def __init__(self):
        self.buff = None
        self.index = 0

    def __next__(self):
        if self.buff is None or self.index == len(self.buff):
            self.buff = sys.stdin.readline().split()
            self.index = 0
        val = self.buff[self.index]
        self.index += 1
        return val

    def next_int(self):
        return int(next(self))

    def cal(self, s):
        if len(s) == 1:
            return s[0]
        if s[0] == 0:
            return self.cal(s[1:])
        v = 1
        for c in s:
            v *= c
        return v

    def solve(self):
        n = self.next_int()
        m = self.next_int()
        h = self.next_int()
        f = [self.next_int() for _ in range(0, m)]
        l = [self.next_int() for _ in range(0, n)]
        for i in range(0, n):
            rs = []
            for j in range(0, m):
                if self.next_int() == 0:
                    rs.append(0)
                else:
                    rs.append(min(f[j], l[i]))
            print(' '.join([str(x) for x in rs]))


def __starting_point():
    Main().solve()

__starting_point()

from sys import stdin

n, m, h = list(map(int, stdin.readline().split()))

cols = list(map(int, stdin.readline().split()))
rows = list(map(int, stdin.readline().split()))

top = [list(map(int, stdin.readline().split())) for i in range(n)]

ans = [[0 if top[i][f] == 0 else min(rows[i], cols[f]) for f in range(m)] for i in range(n)]
print('\n'.join([' '.join(map(str, r)) for r in ans]))



n,m,h = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [list(map(int,input().split())) for _ in range(n)]

for i in range(n):
	for j in range(m):
		if c[i][j] == 1:
			c[i][j] = min(a[j],b[i])

for i in range(n):
	print(*c[i])

n, m, h = [int(i) for i in input().split()]
front = [int(i) for i in input().split()] # len = m
left = [int(i) for i in input().split()] # len = n
A = []
for i in range(n):
    B = [int(i) for i in input().split()]
    A.append(B)

ans = [[0 for i in range(m)] for j in range(n)]

for i in range(n):
    for j in range(m):
        if A[i][j]:
            ans[i][j] = min(front[j], left[i])
for i in ans:
    print(*i)


from sys import stdin, stdout
n,m,h=map(int,input().split())
front=list(map(int,input().split()))
side=list(map(int,input().split()))
top=[None]*n
for i in range(n):
         top[i]=list(map(int,input().split()))
         for j in range(m):
                  if(top[i][j]==1):
                           top[i][j]=min(front[j],side[i])
for i in range(n):
         for j in top[i]:
                  print(j,end=" ")
         print("")

n, m, h = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(n)]
d = [[0] * m for _ in range(n)]

for i in range(n):
    for j in range(m):
        if c[i][j]:
            d[i][j] = min(a[j], b[i])

for i in d:
    print(*i)


kk=lambda:list(map(int,input().split()))
ll=lambda:list(kk())
n,m,h = kk()
front = ll()
left = ll()
for col in range(n):
	tbp = []
	line = kk()
	for row,l in enumerate(line):
		tbp.append(0 if l == 0 else min(front[row], left[col]))
	print(*tbp)



n,m,h=[int(k) for k in input().split(" ")]

cols=[int(k) for k in input().split(" ")]
rows=[int(k) for k in input().split(" ")]
mat=[]
res=[[0 for j in range(m)] for i in range(n)]
for i in range(n):
    mat+=[[int(k) for k in input().split(" ")]]

for i in range(n):
    for j in range(m):
        res[i][j]=str(mat[i][j]*min(cols[j],rows[i]))
    print(" ".join(res[i]))

    



N, M, H = map(int, input().split())

FV = list(map(int, input().split()))
LV = list(map(int, input().split()))

TV = []

for n in range(N):
    row = list(map(int, input().split()))
    TV.append(row)
    
for r in range(N):
    for c in range(M):
        if TV[r][c] == 1:
            TV[r][c] = min(FV[c], LV[r])

for t in TV:
    for s in t:
        print(s, end=' ')
    print()
    
    



from collections import defaultdict
n,m,h = list(map(int,input().split()))
a = list(map(int,input().split()))  # m items
b = list(map(int,input().split()))  # n items 0<=b<=h


front = defaultdict(int)
for i, x in enumerate(a):
    front[i] = x
left = defaultdict(int)
for i, x in enumerate(b):
    left[i] = x

out = [[0 for x in range(m)] for y in range(n)]
for i in range(n):
    x = list(map(int,input().split())) # m items
    for j, b in enumerate(x):
        if b:
            out[i][j] = min(left[i],front[j])

for x in out:
    print(*x)


N, M, H = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
t = [list(map(int, input().split())) for i in range(N)]
for i in range(N):
    for j in range(M):
        if not t[i][j]: continue
        t[i][j] = min(B[i], A[j])
    print(' '.join(map(str, t[i])))


n, m, h = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
H = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
    for j in range(m):
        if H[i][j] == 1:
            H[i][j] = min(A[j], B[i])
for s in H:
    print(*s)


n, m, h = list(map(int, input().split()))
maks_kol = list(map(int, input().split()))
maks_wie = list(map(int, input().split()))
gora = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	for j in range(m):
		if gora[i][j] == 1:
			gora[i][j] = min(maks_wie[i], maks_kol[j])
for j in range(n):
	for i in range(m):
		if i < m - 1:
			print(gora[j][i], end = " ")
		else:
			print(gora[j][i], end = "\n")


#Bhargey Mehta (Sophomore)
#DA-IICT, Gandhinagar
import sys, math, queue
sys.setrecursionlimit(1000000)
#sys.stdin = open("input.txt", "r")
MOD = 10**9+7

n, m, h = map(int, input().split())
front = list(map(int, input().split()))
side = list(map(int, input().split()))
top = []
for i in range(n):
    top.append(list(map(int, input().split())))
ans = [[-1 for i in range(m)] for j in range(n)]

for i in range(n):
    for j in range(m):
        if top[i][j] == 0:
            ans[i][j] = 0
        else:
            ans[i][j] = min(front[j], side[i])

for row in ans:
    print(*row)

n,m,h=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[[int(i) for i in input().split()] for j in range(n)]

for i in range(n):
    target = b[i]
    for j in range(m):
        if c[i][j]==0: continue
        if a[j] < target: continue
        c[i][j] = target
for j in range(m):
    target = a[j]
    for i in range(n):
        if c[i][j]==0: continue
        if b[i] < target: continue
        c[i][j] = target
for row in c:
    for col in row:
        print(col,end=' ')
    print()


import sys

input = sys.stdin.readline

n, m, h = map(int, input().split())

front = list(map(int, input().split()))
left = list(map(int, input().split()))
grid = []

for i in range(n):
    grid.append(list(map(int, input().split())))

for i in range(n):
    for j in range(m):
        if grid[i][j] == 1:
            grid[i][j] = min(front[j], left[i])

for row in grid:
    print(' '.join([str(x) for x in row]))

import sys
input = sys.stdin.readline

n,m,h=list(map(int,input().split()))

A=list(map(int,input().split()))

B=list(map(int,input().split()))

MAP=[list(map(int,input().split())) for i in range(n)]

for i in range(n):
    for j in range(m):
        if MAP[i][j]==0:
            continue

        MAP[i][j]=min(A[j],B[i])

for m in MAP:
    print(*m)


n,m,h = list(map(int,input().split()))

front = [int(x) for x in input().split()] # m
left = [int(x) for x in input().split()] # n

top = [[int(x) for x in input().split()] for _ in range(n)]

box = [[[top[nn][mm]]*h for mm in range(m)] for nn in range(n)]

for j in range(m):
    for i in range(n):
        for z in range(front[j],h):
            box[i][j][z] = 0

for i in range(n):
    for j in range(m):
        for z in range(left[i],h):
            box[i][j][z] = 0

for i in range(n):
    print(' '.join(str(sum(box[i][j])) for j in range(m)))




n, m, h = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
table = [list(map(int, input().split())) for i in range(n)]
answer = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
    for j in range(m):
        if table[i][j] == 1:
            answer[i][j] = min(a[j], b[i])
for i in range(n):
    for j in range(m):
        print(answer[i][j], end=' ')
    print()

            


n,m,h = list(map(int,input().split()))

a = list(map(int,input().split()))
b = list(map(int,input().split()))
l = [[0] * m for _ in range(n)]
for i in range(n):
    for j in range(m):
        l[i][j] = min(a[j], b[i])
for i in range(n):
    p = list(map(int,input().split()))
    for j in range(m):
        if p[j] == 0:
            l[i][j] = 0
for i in l:
    print(*i)


import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n,m,h = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = [list(map(int,input().split())) for i in range(n)]
ans = [[0]*m for i in range(n)]
for i in range(n):
    for j in range(m):
        if x[i][j] == 1:
            ans[i][j] = min(b[i],a[j])
for i in range(n):
    print(*ans[i])