Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!

Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a_1, a_2, ..., a_{n} denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b_1, b_2, ..., b_{m} denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.

Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.


-----Input-----

The first line contains two numbers n and m (2 ≤ n, m ≤ 100) — the dimensions of the matrix.

The second line contains n numbers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9), where a_{i} is the xor of all elements in row i.

The third line contains m numbers b_1, b_2, ..., b_{m} (0 ≤ b_{i} ≤ 10^9), where b_{i} is the xor of all elements in column i.


-----Output-----

If there is no matrix satisfying the given constraints in the first line, output "NO".

Otherwise, on the first line output "YES", and then n rows of m numbers in each c_{i}1, c_{i}2, ... , c_{im} (0 ≤ c_{ij} ≤ 2·10^9) — the description of the matrix.

If there are several suitable matrices, it is allowed to print any of them.


-----Examples-----
Input
2 3
2 9
5 3 13

Output
YES
3 4 5
6 7 8

Input
3 3
1 7 6
2 15 12

Output
NO

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Flows and cuts

Mathematics

Constructive algorithms


Solutions:
def pr(H, W, mtx, vec):
	for y in range(H):
		print(*[mtx[y][x] for x in range(W)], sep='', end=' ')
		print(vec[y])
	print()

def solveb(N, M, A, B, bit):
	mtx = [bytearray(N * M) for _ in range(N + M)]
	for m in range(M):
		for i in range(m, N * M, M):
			mtx[m][i] = 1
	for n in range(N):
		for i in range(M):
			mtx[M + n][n * M + i] = 1
	vec = bytearray(N + M)
	for m in range(M):
		vec[m] = B[m] >> bit & 1
	for n in range(N):
		vec[M + n] = A[n] >> bit & 1
	H = N + M
	W = N * M
	ox = 0
	bottomy = H
	for oy in range(H):
		if ox == W:
			bottomy = oy
			break
		if mtx[oy][ox] == 0:
			while True:
				rep = False
				for y in range(oy + 1, H):
					if mtx[y][ox] == 1:
						row = mtx[oy]
						mtx[oy] = mtx[y]
						mtx[y] = row
						v = vec[oy]
						vec[oy] = vec[y]
						vec[y] = v
						break
				if mtx[oy][ox] == 0:
					ox += 1
					if ox < W:
						rep = True
				if not rep:
					break
		if ox == W:
			bottomy = oy
			break
		for y in range(oy + 1, H):
			if mtx[y][ox] == 1:
				for x in range(ox, W):
					mtx[y][x] ^= mtx[oy][x]
				vec[y] ^= vec[oy]
		ox += 1
	for y in range(bottomy, H):
		if vec[y] == 1:
			return None
	for oy in range(bottomy - 1, -1, -1):
		ox = -1
		for x in range(0, W):
			if mtx[oy][x] == 1:
				ox = x
				break
		assert ox != -1
		for y in range(oy):
			if mtx[y][ox] == 1:
				for x in range(W):
					mtx[y][x] ^= mtx[oy][x]
				vec[y] ^= vec[oy]
	ans = bytearray(N * M)
	for y in range(bottomy):
		ox = -1
		for x in range(W):
			if mtx[y][x] == 1:
				ox = x
				break
		assert ox != -1
		ans[ox] = vec[y]
	return ans

def solve(N, M, A, B):
	ans = [0] * (N * M)
	for bit in range(32):
		ansb = solveb(N, M, A, B, bit)
		if ansb is None:
			return None
		for i in range(N * M):
			ans[i] |= ansb[i] << bit
	result = [[0] * M for _ in range(N)]
	for y in range(N):
		for x in range(M):
			result[y][x] = ans[y * M + x]
	return result

def main():
	(N, M) = [int(e) for e in input().split(' ')]
	A = [int(e) for e in input().split(' ')]
	B = [int(e) for e in input().split(' ')]
	assert len(A) == N
	assert len(B) == M
	ans = solve(N, M, A, B)
	if ans is None:
		print('NO')
		return
	print('YES')
	for row in ans:
		print(*row)
main()


from functools import reduce

def xor_array(ar):
	return reduce(lambda x, y: x ^ y, ar)
(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
x = xor_array(a)
y = xor_array(b)
if x != y:
	print('NO')
else:
	print('YES')
	print(x ^ a[0] ^ b[0], *b[1:])
	for i in range(1, n):
		print(a[i], '0 ' * (m - 1))


from functools import reduce
(n, m) = (int(x) for x in input().split())
rs = [int(x) for x in input().split()]
cs = [int(x) for x in input().split()]
r = reduce(lambda a, b: a ^ b, rs, 0)
c = reduce(lambda a, b: a ^ b, cs, 0)
if r != c:
	print('NO')
else:
	print('YES')
	t = r ^ rs[0] ^ cs[0]
	print(t, end='')
	for j in range(1, m):
		print(' ', cs[j], end='', sep='')
	print()
	for i in range(1, n):
		print(rs[i], end='')
		for j in range(1, m):
			print(' 0', end='')
		print()


I = input
P = print
R = range
I()
a = [int(i) for i in I().split()]
b = [int(i) for i in I().split()]
n = len(a)
m = len(b)
x = b[-1]
for i in R(n - 1):
	x ^= a[i]
y = a[-1]
for i in R(m - 1):
	y ^= b[i]
if x != y:
	P('NO')
	return
P('YES')
for i in R(n - 1):
	P('0 ' * (m - 1) + str(a[i]))
for i in R(m - 1):
	P(b[i], end=' ')
P(x)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [[0] * m for i in range(n)]
l = 0
z = 0
p = 0
for i in a:
	l = l ^ i
for j in b:
	p = p ^ j
for w in range(1, m):
	z = z ^ b[w]
if l != p:
	print('NO')
else:
	print('YES')
	for i in range(1, m):
		ans[0][i] = b[i]
	for j in range(1, n):
		ans[j][0] = a[j]
	ans[0][0] = a[0] ^ z
	for i in range(len(ans)):
		print(*ans[i])


t = 1
for test in range(1, t + 1):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	arr = [[0 for i in range(m)] for j in range(n)]
	tmp = 0
	for i in a:
		tmp = tmp ^ i
	for i in b:
		tmp = tmp ^ i
	if tmp != 0:
		print('NO')
	else:
		print('YES')
		row = 0
		while row < n - 1:
			arr[row][-1] = a[row]
			b[m - 1] = a[row] ^ b[m - 1]
			row += 1
		for i in range(m):
			arr[n - 1][i] = b[i]
		for i in range(n):
			print(*arr[i])


import sys
from array import array
from operator import xor
from functools import reduce

def readline():
	return sys.stdin.buffer.readline().decode('utf-8')
(n, m) = map(int, readline().split())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
mat = [[0] * m for _ in range(n)]
for i in range(1, m):
	mat[0][i] = b[i]
mat[0][0] = a[0] ^ reduce(xor, mat[0])
for i in range(1, n):
	mat[i][0] = a[i]
if reduce(xor, (mat[i][0] for i in range(n))) == b[0]:
	print('YES')
	for row in mat:
		print(*row)
else:
	print('NO')


import sys
from collections import defaultdict
(n, m) = map(int, sys.stdin.readline().split())
a = 0
rows = list(map(int, sys.stdin.readline().split()))
r = 0
for i in range(n):
	a ^= rows[i]
	r ^= rows[i]
cols = list(map(int, sys.stdin.readline().split()))
for i in range(m):
	a ^= cols[i]
if a != 0:
	print('NO')
	sys.exit()
ans = [[0 for i in range(m)] for x in range(n)]
r = 0
for i in range(m - 1):
	r ^= cols[i]
	ans[0][i] = cols[i]
ans[0][m - 1] = rows[0] ^ r
for i in range(1, n - 1):
	ans[i][m - 1] = rows[i]
y = 0
for i in range(n - 1):
	y ^= ans[i][m - 1]
ans[n - 1][m - 1] = y ^ cols[-1]
print('YES')
for i in range(n):
	print(*ans[i])


USE_STDIO = False
if not USE_STDIO:
	try:
		import mypc
	except:
		pass

def getXor(a):
	ans = 0
	for x in a:
		ans ^= x
	return ans

def main():
	(n, m) = map(int, input().split(' '))
	a = [x for x in map(int, input().split(' '))]
	b = [x for x in map(int, input().split(' '))]
	rxor = getXor(a)
	cxor = getXor(b)
	if rxor != cxor:
		print('NO')
		return
	x = [[0] * m for _ in range(n)]
	if n >= m:
		x[0][0] = a[0]
		for i in range(1, m):
			x[i][i - 1] = b[i - 1] ^ x[i - 1][i - 1]
			x[i][i] = a[i] ^ x[i][i - 1]
		for i in range(m, n):
			x[i][-1] = a[i]
	else:
		x[0][0] = b[0]
		for i in range(1, n):
			x[i - 1][i] = a[i - 1] ^ x[i - 1][i - 1]
			x[i][i] = b[i] ^ x[i - 1][i]
		for i in range(n, m):
			x[-1][i] = b[i]
	print('YES')
	for i in range(n):
		print(' '.join(map(str, x[i])))
main()


def sum(x):
	ans = 0
	for i in x:
		ans ^= i
	return ans
i = lambda : [*map(int, input().split())]
(n, m) = i()
a = i()
b = i()
if sum(a) != sum(b):
	print('NO')
	quit()
print('YES')
one = sum(a[1:]) ^ b[0]
print(one, end=' ')
for i in b[1:]:
	print(i, end=' ')
print()
st = ''
for i in range(m - 1):
	st += '0 '
for i in a[1:]:
	print(i, end=' ')
	print(st)


(r, c) = map(int, input().split())
row = list(map(int, input().split()))
col = list(map(int, input().split()))
store = [[0 for i in range(c)] for j in range(r)]
xor_bl = col[0]
for i in range(r - 1):
	xor_bl = xor_bl ^ row[i]
xor_br = xor_bl ^ row[-1]
for i in range(1, c - 1):
	xor_br = xor_br ^ col[i]
if xor_br != col[-1]:
	print('NO')
else:
	print('YES')
	for i in range(r):
		store[i][0] = row[i]
	for i in range(c):
		store[r - 1][i] = col[i]
	store[r - 1][0] = xor_bl
	for i in store:
		for j in i:
			print(j, end=' ')
		print()


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [[0] * m for i in range(n)]
x = 0
for i in range(n):
	x ^= a[i]
y = 0
for i in range(m):
	y ^= b[i]
if x != y:
	print('NO')
	exit()
y = y ^ b[0]
c[0][0] = y ^ a[0]
for i in range(1, m):
	c[0][i] = b[i]
for i in range(1, n):
	c[i][0] = a[i]
print('YES')
for i in range(n):
	print(*c[i])


from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import sys
sys.setrecursionlimit(10 ** 9)
(n, m) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
ans = []
for i in range(n):
	ka = [0] * m
	ans.append(ka)
for i in range(n - 1):
	ans[i][-1] = l1[i]
z = 0
for i in range(m - 1):
	ans[-1][i] = l2[i]
	z ^= l2[i]
ka = l1[-1] ^ z
z = ka
for i in range(n):
	z ^= ans[i][-1]
if z == l2[-1]:
	print('YES')
	ans[-1][-1] = ka
	for i in ans:
		print(*i)
else:
	print('NO')


import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
from collections import defaultdict
INF = pow(2, 63)

def solve(n, m, arrn, arrm):

	def bitat(num, shift):
		return num >> shift & 1

	def set_bit(value, bit):
		return value | 1 << bit
	mask = pow(2, 63) - 1

	def unset_bit(value, bit):
		return value & (mask ^ 1 << bit)

	def update_bit(value, bit, bitval):
		if bitval:
			return set_bit(value, bit)
		return unset_bit(value, bit)
	ans = [[0] * m for _ in range(n)]
	for b in range(32):
		unsat_cnt = 0
		for i in [0]:
			bit = 0
			for j in range(m):
				bit = bit ^ bitat(arrm[j], b)
				if bitat(arrm[j], b):
					ans[i][j] = set_bit(ans[i][j], b)
			if bit != bitat(arrn[i], b):
				unsat_cnt += 1
				bitt = bitat(ans[i][-1], b) ^ 1
				ans[i][-1] = update_bit(ans[i][-1], b, bitt)
			for k in range(1, n):
				if bitat(arrn[k], b):
					unsat_cnt += 1
					ans[k][-1] = set_bit(ans[k][-1], b)
		if unsat_cnt % 2 != 0:
			return False
	return ans

@bootstrap
def rec(i, k, arr, mp, f=0):
	pass

def main():
	[n, m] = list(map(int, input().strip().split()))
	arrn = list(map(int, input().strip().split()))
	arrm = list(map(int, input().strip().split()))
	ans = solve(n, m, arrn, arrm)
	if not ans:
		print('NO')
		return
	print('YES')
	for i in range(n):
		ans[i] = [str(x) for x in ans[i]]
		print(' '.join(ans[i]))
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
f1 = 0
f2 = 0
for i in range(len(a)):
	f1 ^= a[i]
for i in range(len(b)):
	f2 ^= b[i]
if f1 != f2:
	print('NO')
	exit(0)
print('YES')
ans = []
for i in range(n):
	ans.append([0 for x in range(m)])
deg = 1
while deg <= 1000000000:
	flag = b[0] & deg
	for i in range(n - 1):
		if a[i] & deg == deg:
			ans[i][0] += deg
			flag ^= deg
	ans[-1][0] += flag
	for i in range(1, m):
		ans[-1][i] += b[i] & deg
	deg *= 2
for i in range(n):
	for j in range(m):
		print(ans[i][j], end=' ')
	print()


from functools import reduce
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [[0] * m for i in range(n)]
if reduce(lambda x, y: x ^ y, a) ^ reduce(lambda x, y: x ^ y, b) != 0:
	print('NO')
else:
	stop = False
	while not stop:
		for i in range(n):
			for j in range(m):
				x = a[i] & b[j]
				a[i] ^= x
				b[j] ^= x
				c[i][j] |= x
		stop = True
		for i in range(n):
			for j in range(m):
				x = a[i] | b[j]
				if x:
					a[i] ^= x
					b[j] ^= x
					c[i][j] |= x
					stop = False
					break
			if not stop:
				break
	print('YES')
	for i in range(n):
		print(*c[i])


(n, m) = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
res = []
for i in range(n - 1):
	cur = []
	if a[i] % 2 == 0:
		tmp = a[i] + 1
	else:
		tmp = a[i] - 1
	cur.append('1')
	l = m - 2
	for j in range(2, 2 + l):
		cur.append('0')
	cur.append(str(tmp))
	res.append(cur)
last = []
for i in range(m):
	cur = b[i]
	for j in range(n - 1):
		cur ^= int(res[j][i])
	last.append(str(cur))
val = 0
for i in range(m):
	val ^= int(last[i])
if val == a[n - 1]:
	print('YES')
	for i in range(n - 1):
		print(' '.join(res[i]))
	print(' '.join(last))
else:
	print('NO')


(n, m) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
import copy
C = copy.copy(B)
ans = [[0] * m for i in range(n)]
for i in range(n - 1):
	for j in range(m):
		if j == 0:
			ans[i][j] = A[i]
			C[0] ^= A[i]
		else:
			ans[i][j] = 0
for j in range(m):
	ans[n - 1][j] = C[j]
flag = True
for i in range(n):
	t = 0
	for j in range(m):
		t ^= ans[i][j]
	if t != A[i]:
		flag = False
		break
for j in range(m):
	t = 0
	for i in range(n):
		t ^= ans[i][j]
	if t != B[j]:
		flag = False
		break
if flag:
	print('YES')
	for i in range(n):
		print(*ans[i])
else:
	print('NO')


def xor(a):
	x = 0
	for i in a:
		x ^= i
	return x
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if xor(a) != xor(b):
	print('NO')
else:
	print('YES')
	b[0] = b[0] ^ xor(a[1:])
	print(*b)
	for i in range(n - 1):
		print(a[i + 1], ' 0' * (m - 1))


(n, m) = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
aa = 0
bb = 0
cc = 0
for i in range(max(n, m)):
	if i == n - 1:
		cc = aa
	if i < n:
		aa ^= a[i]
	if i < m:
		bb ^= b[i]
if aa != bb:
	print('NO')
else:
	print('YES')
	for i in range(n - 1):
		for j in range(m):
			if j < m - 1:
				print('0', end=' ')
			else:
				print(a[i])
	for j in range(m - 1):
		print(b[j], end=' ')
	print(cc ^ b[-1])


i = lambda : [*map(int, input().split())]
(n, m) = i()
(a, b) = (i(), i())

def s(a):
	r = 0
	for i in a:
		r ^= i
	return r
if s(a) == s(b):
	print('YES')
	b[0] ^= s(a[1:])
	print(*b)
	for i in a[1:]:
		print(str(i) + ' 0' * (m - 1))
else:
	print('NO')


import sys
import math
input = sys.stdin.readline
from functools import cmp_to_key

def pi():
	return int(input())

def pl():
	return int(input(), 16)

def ti():
	return list(map(int, input().split()))

def ts():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
f = []

def factMod(n, m):
	global f
	f = [1 for i in range(n + 1)]
	f[0] = 1
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % m

def fact(n):
	global f
	f = [1 for i in range(n)]
	for i in range(1, n):
		f[i] = f[i - 1] * i

def fast_mod_exp(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b = b >> 1
	return res

def inverseMod(n, m):
	return fast_mod_exp(n, m - 2, m)

def ncrMod(n, r, m):
	if r == 0:
		return 1
	if n < r:
		return 0
	return f[n] * inverseMod(f[n - r], m) % m * inverseMod(f[r], m) % m

def ncr(n, r):
	if r == 0:
		return 1
	if n < r:
		return 0
	return f[n] / (f[r] * f[n - r])

def nc2(n):
	return n * (n - 1) / 2

def main():
	D()

def D():
	[n, m] = ti()
	(a, b) = (ti(), ti())
	xa = a[0]
	xb = b[0]
	for i in range(1, n):
		xa = xa ^ a[i]
	for i in range(1, m):
		xb = xb ^ b[i]
	if xa != xb:
		print('NO')
		return
	ans = [[-1 for i in range(m)] for j in range(n)]
	a00 = a[0]
	for i in range(1, m):
		a00 = a00 ^ b[i]
	for i in range(1, m):
		ans[0][i] = b[i]
	ans[0][0] = a00
	for i in range(1, n):
		ans[i][0] = a[i]
	for i in range(n):
		for j in range(m):
			ans[i][j] = 0 if ans[i][j] == -1 else ans[i][j]
	print('YES')
	for i in range(n):
		print(*ans[i])
main()


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xor = 0
for ai in a:
	xor = xor ^ ai
for bi in b:
	xor = xor ^ bi
if xor != 0:
	print('NO')
else:
	ans = []
	for i in range(n):
		ans.append([0] * m)
	xor = 0
	for i in range(m - 1):
		ans[-1][i] = b[i]
		xor = xor ^ b[i]
	for i in range(n - 1):
		ans[i][-1] = a[i]
	ans[-1][-1] = xor ^ a[-1]
	print('YES')
	for an in ans:
		s = ''
		for ai in an:
			s += str(ai) + ' '
		print(s)


from __future__ import print_function
from sys import stdin
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n, m) = gil()
(r, c) = (gil(), gil())
(rv, cv) = (0, 0)
for v in r:
	rv ^= v
for v in c:
	cv ^= v
if rv == cv:
	print('YES')
	x = r[0] ^ cv ^ c[0]
	ans = [[0 for _ in range(m)] for _ in range(n)]
	for j in range(1, m):
		ans[0][j] = c[j]
	for i in range(1, n):
		ans[i][0] = r[i]
	ans[0][0] = x
	for r in ans:
		print(*r)
else:
	print('NO')


def xor(lis):
	ans = lis[0]
	for num in lis[1:]:
		ans = ans ^ num
	return ans
(n, m) = list(map(int, input().split()))
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))
if xor(ai) != xor(bi):
	print('NO')
else:
	print('YES')
	ans = [[1 for i in range(m - 1)] for j in range(n - 1)]
	for i in range(n - 1):
		ans[i] = ans[i] + [ai[i] ^ xor(ans[i])]
	last = []
	for i in range(m - 1):
		last += [(n - 1) % 2 ^ bi[i]]
	last += [xor(last) ^ ai[n - 1]]
	ans += [last]
	for lis in ans:
		print(' '.join(list(map(str, lis))))


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [[0] * m for i in range(n)]
for bit in range(40):
	tmp_a = []
	tmp_b = []
	for i in range(n):
		if 1 << bit & a[i]:
			tmp_a.append(i)
	for i in range(m):
		if 1 << bit & b[i]:
			tmp_b.append(i)
	if len(tmp_a) % 2 != len(tmp_b) % 2:
		print('NO')
		exit()
	tmp = [[0] * m for i in range(n)]
	for i in range(len(tmp_a)):
		if 2 * i + 1 < len(tmp_a):
			tmp[tmp_a[2 * i]][0] += 1
			tmp[tmp_a[2 * i + 1]][0] += 1
		else:
			if len(tmp_a) % 2 == 0:
				pass
			else:
				tmp[tmp_a[-1]][tmp_b[-1]] += 1
			break
	for i in range(len(tmp_b)):
		if 2 * i + 1 < len(tmp_b):
			tmp[0][tmp_b[2 * i]] += 1
			tmp[0][tmp_b[2 * i + 1]] += 1
		else:
			break
	for i in range(n):
		for j in range(m):
			if tmp[i][j] % 2 == 1:
				ans[i][j] += 1 << bit
print('YES')
for i in ans:
	print(*i)


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
bn = 0
for x in b[1:]:
	bn ^= x
an = 0
for x in a[1:]:
	an ^= x
if bn ^ a[0] == an ^ b[0]:
	print('YES')
	arr = [[0 for _ in range(m)] for _ in range(n)]
	arr[0][0] = bn ^ a[0]
	for i in range(1, n):
		arr[i][0] = a[i]
	for i in range(1, m):
		arr[0][i] = b[i]
	for i in range(n):
		print(' '.join(map(str, arr[i])))
else:
	print('NO')


from functools import reduce
(n, m) = (int(x) for x in input().split())
rows = [int(x) for x in input().split()]
cols = [int(x) for x in input().split()]
rx = reduce(lambda a, b: a ^ b, rows, 0)
cx = reduce(lambda a, b: a ^ b, cols, 0)
if rx != cx:
	print('NO')
else:
	print('YES')
	t = rx ^ rows[0] ^ cols[0]
	print(t, end='')
	for j in range(1, m):
		print(' ', cols[j], end='', sep='')
	print()
	for i in range(1, n):
		print(rows[i], end='')
		for j in range(1, m):
			print(' 0', end='')
		print()


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = [[int(0) for i in range(m)] for j in range(n)]
for i in range(n):
	ans[i][0] = a[i]
for i in range(m):
	ans[0][i] = b[i]
ans[0][0] = 0
kekw = b[0]
for i in range(1, n):
	kekw ^= a[i]
kekw1 = a[0]
for j in range(1, m):
	kekw1 ^= b[j]
if kekw != kekw1:
	print('NO')
else:
	ans[0][0] = kekw
	print('YES')
	for i in range(n):
		print(*ans[i])


def xor(l):
	c = 0
	for i in l:
		c = c ^ i
	return c
[n, m] = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
if xor(a + b) != 0:
	print('NO')
else:
	print('YES')
	c = [[0] * m for i in range(n)]
	for i in range(1, n):
		c[i][0] = a[i]
	for i in range(1, m):
		c[0][i] = b[i]
	c[0][0] = xor(a + [a[0]] + [b[0]])
	for i in c:
		print(' '.join([str(x) for x in i]))


(n, m) = map(int, input().split())
xor_sum = []
a = []
for i in range(2):
	a.append(list(map(int, input().split())))
	xor_sum.append(0)
	for x in a[-1]:
		xor_sum[-1] ^= x
if xor_sum[0] != xor_sum[1]:
	print('NO')
	exit(0)
print('YES')
for i in range(n):
	for j in range(m):
		if i < n - 1 and j < m - 1:
			print(0, end=' ')
		elif i == n - 1 and j < m - 1:
			print(a[1][j], end=' ')
		elif i < n - 1 and j == m - 1:
			print(a[0][i], end=' ')
		else:
			t = a[0][-1]
			for k in range(0, m - 1):
				t ^= a[1][k]
			print(t, end=' ')
	print()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = a[-1]
y = b[-1]
for j in range(m - 1):
	x = x ^ b[j]
for j in range(n - 1):
	y = y ^ a[j]
if x != y:
	print('NO')
else:
	print('YES')
	c = []
	for i in range(n):
		c.append([])
	for i in range(n):
		for j in range(m):
			if i != n - 1 and j != m - 1:
				c[i].append(0)
			elif i != n - 1 and j == m - 1:
				c[i].append(a[i])
			elif i == n - 1 and j != m - 1:
				c[i].append(b[j])
			else:
				c[i].append(x)
	for j in c:
		print(*j)


import sys
import io
stream_enable = 0
inpstream = '\n2 3\n2 9\n5 3 13\n'
if stream_enable:
	sys.stdin = io.StringIO(inpstream)
	input()

def inpmap():
	return list(map(int, input().split()))
(n, m) = inpmap()
a = inpmap()
b = inpmap()
x = b[-1]
for t in a[:-1]:
	x ^= t
y = a[-1]
for t in b[:-1]:
	y ^= t
if x == y:
	print('YES')
else:
	print('NO')
	exit()
for i in range(n - 1):
	print('0 ' * (m - 1), end='')
	print(a[i])
print(*b[:-1], end=' ' if len(b) > 1 else '')
print(x)


from sys import stdin, stdout
from math import log2
(n, m) = map(int, stdin.readline().split())
strings = list(map(int, stdin.readline().split()))
columns = list(map(int, stdin.readline().split()))
ans = [[0 for i in range(m)] for j in range(n)]
for i in range(n - 1):
	ans[i][m - 1] = strings[i]
for i in range(m - 1):
	ans[n - 1][i] = columns[i]
cnt = strings[n - 1]
for i in range(m):
	cnt ^= ans[n - 1][i]
ans[n - 1][m - 1] = cnt
cnt = 0
for j in range(n):
	cnt ^= ans[j][m - 1]
if cnt != columns[m - 1]:
	stdout.write('NO\n')
else:
	stdout.write('YES\n')
	for i in range(n):
		for j in range(m):
			stdout.write(str(ans[i][j]) + ' \n'[j + 1 == m])


import sys
import math
import operator as op
from functools import reduce

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom
(n, m) = read_int_line()
a = read_int_line()
b = read_int_line()
x1 = 0
for i in a:
	x1 = x1 ^ i
x2 = 0
for i in b:
	x2 = x2 ^ i
if x1 != x2:
	print('NO')
else:
	print('YES')
	ans = [[0 for i in range(m)] for j in range(n)]
	v1 = a[0]
	for j in range(1, m):
		v1 = v1 ^ b[j]
	for j in range(1, m):
		ans[0][j] = b[j]
	ans[0][0] = v1
	for i in range(1, n):
		ans[i][0] = a[i]
	for i in range(n):
		for j in range(m):
			print(ans[i][j], end=' ')
		print()


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(a, b):
	xor_a = a[0]
	for i in range(1, len(a)):
		xor_a ^= a[i]
	xor_b = b[0]
	for i in range(1, len(b)):
		xor_b ^= b[i]
	if xor_a != xor_b:
		return None
	result = [[0 for x in range(len(b))] for y in range(len(a))]
	result[0][0] = xor_a ^ b[0] ^ a[0]
	for i in range(1, len(b)):
		result[0][i] = b[i]
	for i in range(1, len(a)):
		result[i][0] = a[i]
	return result
(n, m) = arr_in()
a = arr_in()
b = arr_in()
result = solve(a, b)
out('NO' if result is None else 'YES')
if result is not None:
	for row in result:
		arr_out(row)


(n, m) = map(int, input().split())
r = list(map(int, input().split()))
c = list(map(int, input().split()))
mat = [[0] * m for i in range(n)]
fail = False
for p in range(60):
	totr = 0
	needr = []
	totc = 0
	needc = []
	for i in range(n):
		if r[i] >> p & 1:
			needr.append(i)
			totr += 1
	for j in range(m):
		if c[j] >> p & 1:
			needc.append(j)
			totc += 1
	if (totr - totc) % 2 != 0:
		fail = True
		break
	else:
		mn = min(len(needr), len(needc))
		for k in range(mn):
			mat[needr[k]][needc[k]] += 1 << p
		if len(needr) > len(needc):
			em = 0
			for i in range(m):
				if i not in needc:
					em = i
					break
			for i in range(mn, len(needr)):
				mat[needr[i]][em] += 1 << p
		else:
			em = 0
			for i in range(n):
				if i not in needr:
					em = i
					break
			for i in range(mn, len(needc)):
				mat[em][needc[i]] += 1 << p
if fail:
	print('NO')
else:
	print('YES')
	for i in mat:
		print(*i)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xor1 = 0
xor2 = 0
for i in range(n):
	xor1 = xor1 ^ a[i]
for i in range(m):
	xor2 = xor2 ^ b[i]
if xor1 != xor2:
	print('NO')
	exit()
else:
	mat = [[0 for i in range(m)] for i in range(n)]
	print('YES')
	for i in range(n - 1):
		mat[i][m - 1] = a[i]
	for j in range(m - 1):
		mat[n - 1][j] = b[j]
	xor3 = xor2 ^ b[-1]
	mat[n - 1][m - 1] = xor3 ^ a[n - 1]
	for i in range(n):
		print(*mat[i])


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(t1, t2) = (0, 0)
for i in a:
	t1 ^= i
for i in b:
	t2 ^= i
if t1 != t2:
	print('NO')
	exit()
print('YES')
for i in range(0, n - 1):
	for j in range(0, m - 1):
		print(0, end=' ')
	print(a[i])
for i in range(0, m - 1):
	print(b[i], end=' ')
print(t2 ^ b[m - 1] ^ a[n - 1])


from functools import reduce
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if reduce(lambda x, y: x ^ y, a) != reduce(lambda x, y: x ^ y, b):
	print('NO')
else:
	print('YES')
	for row in range(n - 1):
		for col in range(m - 1):
			print(0, end=' ')
		print(a[row])
	for col in range(m - 1):
		print(b[col], end=' ')
	print(reduce(lambda x, y: x ^ y, b[:-1]) ^ a[n - 1])


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
full_xor = 0
for ai in a:
	full_xor ^= ai
incorrect = full_xor
for bi in b:
	incorrect ^= bi
if incorrect:
	print('NO')
else:
	print('YES')
	x = a.pop()
	for ai in a:
		print(*(ai,) + (0,) * (m - 1))
	b[0] ^= full_xor ^ x
	print(*b)


from sys import stdin, stdout

def rint():
	return map(int, stdin.readline().split())
(n, m) = rint()
a = list(rint())
b = list(rint())
ans = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	if i != n - 1:
		for j in range(m - 1):
			ans[i][j] = 0
		ans[i][m - 1] = a[i]
	else:
		for j in range(m - 1):
			ans[i][j] = b[j]
		row_xor = 0
		for j in range(m - 1):
			row_xor = row_xor ^ ans[i][j]
		col_xor = 0
		for j in range(n - 1):
			col_xor = col_xor ^ ans[j][m - 1]
		if row_xor ^ a[n - 1] == col_xor ^ b[m - 1]:
			ans[i][m - 1] = row_xor ^ a[n - 1]
		else:
			print('NO')
			exit()
print('YES')
for i in range(n):
	print(*ans[i])


import sys
(n, m) = map(int, input().split())
zeilen = list(map(int, input().split()))
spalten = list(map(int, input().split()))
if (sum(zeilen) - sum(spalten)) % 2:
	print('NO')
	sys.exit()
uzeilen = [[i for (i, z) in enumerate(zeilen) if z & 1 << b] for b in range(32)]
uspalten = [[i for (i, z) in enumerate(spalten) if z & 1 << b] for b in range(32)]
lenz = [len(l) for l in uzeilen]
lens = [len(l) for l in uspalten]
for (lz, ls) in zip(lenz, lens):
	if (lz - ls) % 2:
		print('NO')
		sys.exit()
res = [[0 for i in range(m)] for _ in range(n)]
for b in range(32):
	for (z, s) in zip(uzeilen[b], uspalten[b]):
		res[z][s] |= 1 << b
	if lenz[b] > lens[b]:
		for (z1, z2) in zip(uzeilen[b][lens[b]::2], uzeilen[b][lens[b] + 1::2]):
			res[z1][0] |= 1 << b
			res[z2][0] |= 1 << b
	if lenz[b] < lens[b]:
		for (s1, s2) in zip(uspalten[b][lenz[b]::2], uspalten[b][lenz[b] + 1::2]):
			res[0][s1] |= 1 << b
			res[0][s2] |= 1 << b
print('YES')
print('\n'.join([' '.join(map(str, zeile)) for zeile in res]))


(n, m) = map(int, input().split())
x = map(int, input().split())
y = map(int, input().split())
a = []
for i in x:
	a.append(i)
b = []
for i in y:
	b.append(i)
test = X = 0
for i in a:
	test ^= i
X = test
for i in b:
	test ^= i
if test == 0:
	print('YES')
	print(a[0] ^ b[0] ^ X, end=' ')
	for i in range(1, m):
		print(b[i], end=' ')
	print('')
	for i in range(1, n):
		print(a[i], end=' ')
		for j in range(1, m):
			print(0, end=' ')
		print('')
else:
	print('NO')


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
(xa, xb) = (0, 0)
for v in a:
	xa ^= v
for v in b:
	xb ^= v
if xa != xb:
	print('NO')
else:
	print('YES')
	print(a[0] ^ xb ^ b[0], end=' ')
	for i in range(1, m):
		print(b[i], end=' ')
	for i in range(1, n):
		print()
		print(a[i], end=' ')
		for j in range(1, m):
			print(0, end=' ')


(n, m) = list(map(int, input().split(' ')))
a = list(map(lambda x: bin(int(x))[:2] + bin(int(x))[2:].zfill(30), input().split(' ')))
b = list(map(lambda x: bin(int(x))[:2] + bin(int(x))[2:].zfill(30), input().split(' ')))
cc = [['0b' + ''.zfill(30)] * m for i in range(n)]
aa = 0
bb = 0
for i in range(max(n, m)):
	if i < n:
		aa ^= int(a[i], 2)
	if i < m:
		bb ^= int(b[i], 2)
if aa != bb:
	print('NO')
else:
	print('YES')
	for k in range(30):
		for i in range(n):
			for j in range(m):
				if a[i][-1 - k] == '1' and b[j][-1 - k] == '1':
					cc[i][j] = cc[i][j][:-1 - k] + '1' + (cc[i][j][-k:] if k > 0 else '')
					a[i] = a[i][:-1 - k] + '0' + (a[i][-k:] if k > 0 else '')
					b[j] = b[j][:-1 - k] + '0' + (b[j][-k:] if k > 0 else '')
		aa = -1
		for i in range(n):
			if a[i][-1 - k] == '1':
				if aa == -1:
					aa = i
				else:
					for j in range(m):
						if cc[aa][j][-1 - k] == '0' and cc[i][j][-1 - k] == '0':
							cc[aa][j] = cc[aa][j][:-1 - k] + '1' + (cc[aa][j][-k:] if k > 0 else '')
							cc[i][j] = cc[i][j][:-1 - k] + '1' + (cc[i][j][-k:] if k > 0 else '')
							a[aa] = a[aa][:-1 - k] + '0' + (a[aa][-k:] if k > 0 else '')
							a[i] = a[i][:-1 - k] + '0' + (a[i][-k:] if k > 0 else '')
							break
					aa = -1
		bb = -1
		for j in range(m):
			if b[j][-1 - k] == '1':
				if bb == -1:
					bb = j
				else:
					for i in range(n):
						if cc[i][bb][-1 - k] == '0' and cc[i][j][-1 - k] == '0':
							cc[i][bb] = cc[i][bb][:-1 - k] + '1' + (cc[i][bb][-k:] if k > 0 else '')
							cc[i][j] = cc[i][j][:-1 - k] + '1' + (cc[i][j][-k:] if k > 0 else '')
							b[bb] = b[bb][:-1 - k] + '0' + (b[bb][-k:] if k > 0 else '')
							b[j] = b[j][:-1 - k] + '0' + (b[j][-k:] if k > 0 else '')
							break
					bb = -1
	for i in range(n):
		for j in range(m):
			print(int(cc[i][j], 2), end=' ')
		print('')


from functools import reduce
(m, n) = map(int, input().split())
row = list(map(int, input().split()))
col = list(map(int, input().split()))
sumrow = reduce(lambda x, y: x ^ y, row)
sumcol = reduce(lambda x, y: x ^ y, col)
if sumrow != sumcol:
	print('NO')
else:
	print('YES')
	for i in range(m - 1):
		print((n - 1) * '0 ', end='')
		print(row[i])
	for i in range(n - 1):
		print(col[i], end=' ')
	print(col[n - 1] ^ row[m - 1] ^ sumcol)


import sys
input = sys.stdin.readline

def main():
	(N, M) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	ans = 0
	for a in A:
		ans ^= a
	for b in B:
		ans ^= b
	if ans == 0:
		print('YES')
		a = A[0]
		for b in B[1:]:
			a ^= b
		print(a, end=' ')
		print(*B[1:])
		for j in range(1, N):
			print(A[j], end=' ')
			for k in range(1, M):
				print(0, end=' ')
			print()
	else:
		print('NO')
		return
main()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(x1, x2) = (a[0], b[0])
for i in range(1, n):
	x1 ^= a[i]
for i in range(1, m):
	x2 ^= b[i]
if x1 != x2:
	print('NO')
	exit()
ans = [[0 for i in range(m)] for j in range(n)]
ans[0][0] = a[0] ^ x2 ^ b[0]
for i in range(1, m):
	ans[0][i] = b[i]
for i in range(1, n):
	ans[i][0] = a[i]
print('YES')
for i in range(n):
	print(*ans[i])


import sys

def xor_sum(array):
	result = 0
	for e in array:
		result = result ^ e
	return result

def main():
	(n, m) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	a_sum = xor_sum(a)
	b_sum = xor_sum(b)
	if a_sum != b_sum:
		print('NO')
		return 0
	print('YES')
	matrix = [b]
	for i in range(1, len(a)):
		matrix.append([0 for _ in range(len(b))])
		matrix[-1][0] = a[i]
	matrix[0][0] = b_sum ^ b[0] ^ a[0]
	for line in matrix:
		print(' '.join(map(str, line)))
	return 0

def test(i):
	with open('test_{}.txt'.format(i)) as fin:
		sys.stdin = fin
		main()
sys.exit(main())


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(x, y) = (0, 0)
space = ' '
for i in a:
	x ^= i
for i in b:
	y ^= i
if x != y:
	print('NO')
else:
	print('YES')
	print(a[0] ^ y ^ b[0], end=space)
	for i in range(1, m):
		print(b[i], end=space)
	for i in range(1, n):
		print()
		print(a[i], end=space)
		for j in range(1, m):
			print(0, end=space)


from functools import reduce
(n, m) = list(map(int, input().split()))
ns = list(map(int, input().split()))
ms = list(map(int, input().split()))
xn = reduce(lambda acc, cur: acc ^ cur, ns, 0)
xm = reduce(lambda acc, cur: acc ^ cur, ms, 0)
if xn ^ xm != 0:
	print('NO')
else:
	print('YES')
	print(xm ^ ns[0] ^ ms[0], *ms[1:])
	for i in range(1, n):
		print(ns[i], *[0] * (m - 1))


def f(a, b):
	n = len(a)
	m = len(b)
	r = 0
	for i in a + b:
		r = r ^ i
	if r > 0:
		return [['NO']]
	mt = [[0] * m for _ in range(n)]
	for i in range(min(m, n) - 1):
		mt[i][i + 1] = a[i]
		mt[i + 1][i] = b[i]
		b[i + 1] ^= a[i]
		a[i + 1] ^= b[i]
	for j in range(n - 1, m):
		mt[n - 1][j] = b[j]
	for i in range(m - 1, n):
		mt[i][m - 1] = a[i]
	print('YES')
	return mt
_ = input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
[print(*s) for s in f(a, b)]


import sys, os
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
tc = 1
for test in range(1, tc + 1):
	(n, m) = inp()
	a = inp()
	b = inp()
	xora = xorb = 0
	for i in a:
		xora ^= i
	for i in b:
		xorb ^= i
	if xorb != xora:
		print('NO')
		continue
	print('YES')
	ans = [[0] * m for i in range(n)]
	ans[0][0] = xorb
	for i in range(n):
		ans[i][0] ^= a[i]
	for i in range(m):
		ans[0][i] ^= b[i]
	for i in ans:
		print(*i)


(n, m) = map(int, input().split())
num = list(map(int, input().split()))
lst = list(map(int, input().split()))
a = 0
b = 0
for i in range(n):
	a = a ^ num[i]
for i in range(m):
	b = b ^ lst[i]
if a != b:
	print('NO')
else:
	print('YES')
	ans = []
	for i in range(n):
		ans.append([0] * m)
	for i in range(n):
		ans[i][0] = num[i]
	for i in range(m):
		ans[0][i] = lst[i]
	x = num[0]
	for i in range(1, m):
		x = x ^ lst[i]
	ans[0][0] = x
	for i in range(n):
		print(*ans[i])


import sys
(n, m) = map(int, sys.stdin.readline().split())
rows = list(map(int, sys.stdin.readline().split()))
cols = list(map(int, sys.stdin.readline().split()))
A = rows[0]
for i in range(1, n):
	A ^= rows[i]
B = cols[0]
for i in range(1, m):
	B ^= cols[i]
if A != B:
	print('NO')
else:
	print('YES')
	ans = [[0] * m for i in range(n)]
	x = rows[0]
	for i in range(1, m):
		x ^= cols[i]
	ans[0][0] = x
	for i in range(1, m):
		ans[0][i] = cols[i]
	for j in range(1, n):
		ans[j][0] = rows[j]
	for i in range(n):
		print(*ans[i])