Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner:

$a_{1} OR a_{2} OR \ldots OR a_{k}$ where $a_{i} \in \{0,1 \}$ is equal to 1 if some a_{i} = 1, otherwise it is equal to 0.

Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as A_{ij}. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:

[Image].

(B_{ij} is OR of all elements in row i and column j of matrix A)

Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large.


-----Input-----

The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively.

The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1).


-----Output-----

In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one.


-----Examples-----
Input
2 2
1 0
0 0

Output
NO

Input
2 3
1 1 1
1 1 1

Output
YES
1 1 1
1 1 1

Input
2 3
0 1 0
1 1 1

Output
YES
0 0 0
0 1 0

Difficulty: EASY
Tags: String algorithms

Implementation

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
(m, n) = map(int, input().split())
b = []
for i in range(m):
	b.append(list(map(int, input().split())))
a = [[1 for j in range(n)] for i in range(m)]
for i in range(m):
	for j in range(n):
		if b[i][j] == 0:
			for k in range(m):
				a[k][j] = 0
			for k in range(n):
				a[i][k] = 0
f = 1
temp = [[0 for j in range(n)] for i in range(m)]
for i in range(m):
	if 1 in a[i]:
		for j in range(n):
			temp[i][j] = 1
for i in range(n):
	if 1 in [a[j][i] for j in range(m)]:
		for j in range(m):
			temp[j][i] = 1
for i in range(m):
	for j in range(n):
		if b[i][j] != temp[i][j]:
			f = 0
			print('NO')
			break
	if f == 0:
		break
if f == 1:
	print('YES')
	for i in range(m):
		print(*a[i])


(r, c) = map(int, input().split())
b = []
rcnt = 0
ccnt = 0
for i in range(r):
	x = list(map(int, input().split()))
	b.append(x)
a = [[0 for i in range(c)] for j in range(r)]
cmp = {}
rmp = {}
for i in range(r):
	rmp[i] = 0
	count = 0
	for j in range(c):
		if b[i][j] == 1:
			count += 1
		else:
			break
	if count == c:
		rmp[i] = 1
		rcnt += 1
for i in range(c):
	cmp[i] = 0
	count = 0
	for j in range(r):
		if b[j][i] == 1:
			count += 1
		else:
			break
	if count == r:
		cmp[i] = 1
		ccnt += 1
chk = 0
for i in range(r):
	for j in range(c):
		if b[i][j] == 1:
			if rmp[i] == 1 or cmp[j] == 1:
				continue
			else:
				chk = 1
				break
if chk != 1:
	if rcnt == ccnt or (rcnt >= 1 and ccnt >= 1):
		print('YES')
		for i in rmp.keys():
			for j in cmp.keys():
				if rmp[i] == 1 and cmp[j] == 1:
					a[i][j] = 1
		for i in range(r):
			for j in range(c):
				print(a[i][j], end=' ')
			print()
	else:
		print('NO')
else:
	print('NO')


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
ans = [[0] * m for _ in range(n)]
a = []
su = []
f = 1
for j in range(m):
	x = 0
	for i in range(n):
		if l[i][j] == 0:
			break
		x += 1
	if x == n:
		a.append(j)
for i in range(n):
	if l[i].count(1) == m:
		for j in a:
			ans[i][j] = 1
			su.append([i, j])
k = [[0] * m for _ in range(n)]
for i in su:
	k[i[0]] = [1] * m
	for j in range(n):
		k[j][i[1]] = 1
if l != k:
	print('NO')
else:
	print('YES')
	for i in range(n):
		print(*ans[i])


def isValidMatrix(matrix):
	for row in range(len(matrix)):
		for col in range(len(matrix[0])):
			if matrix[row][col] != 0:
				if not (rowOfOnes(matrix, row) or colOfOnes(matrix, col)):
					return False
	return True

def rowOfOnes(matrix, row):
	for value in matrix[row]:
		if int(value) == 0:
			return False
	return True

def colOfOnes(matrix, col):
	for row in range(len(matrix)):
		if matrix[row][col] == 0:
			return False
	return True

def constructEmptyMatrix(rows, cols):
	matrix = []
	for row in range(rows):
		matrix += [[0] * cols]
	return matrix

def constructMatrixA(matrixA, matrixB):
	global rows
	global cols
	for row in range(rows):
		for col in range(cols):
			if rowOfOnes(matrixB, row) and colOfOnes(matrixB, col):
				matrixA[row][col] = 1
	return matrixA

def printMatrixA(matrixA):
	(rows, cols) = (len(matrixA), len(matrixA[0]))
	for row in range(rows):
		rowString = ''
		for col in range(cols):
			rowString += str(matrixA[row][col])
			rowString += ' '
		rowString = rowString[:-1]
		print(rowString)

def hasNonZero(matrix):
	(rows, cols) = (len(matrixA), len(matrixA[0]))
	for row in range(rows):
		for col in range(cols):
			if matrix[row][col] != 0:
				return True
	return False

def validOutput(matrixA, matrixB):
	(rows, cols) = (len(matrixA), len(matrixA[0]))
	if hasNonZero(matrixA) and hasNonZero(matrixB):
		print('YES')
		printMatrixA(matrixA)
		return
	elif not hasNonZero(matrixA) and (not hasNonZero(matrixB)):
		print('YES')
		printMatrixA(matrixA)
		return
	print('NO')
start = input()
matrixDimensions = [int(x) for x in start.split(' ')]
rows = matrixDimensions[0]
cols = matrixDimensions[1]
matrixB = constructEmptyMatrix(rows, cols)
matrixA = constructEmptyMatrix(rows, cols)
for row in range(rows):
	rowString = input()
	rowValues = rowString.split(' ')
	for col in range(cols):
		matrixB[row][col] = int(rowValues[col])
if not isValidMatrix(matrixB):
	print('NO')
else:
	matrixA = constructMatrixA(matrixA, matrixB)
	validOutput(matrixA, matrixB)


(m, n) = list(map(int, input().split()))
b = []
a = []
new_b = []
for _ in range(m):
	b.append(list(map(int, input().split())))
	a.append([1] * n)
	new_b.append([0] * n)
for (i, row) in enumerate(b):
	for (j, col) in enumerate(row):
		if col == 0:
			for c in range(n):
				a[i][c] = 0
			for r in range(m):
				a[r][j] = 0
for (i, row) in enumerate(b):
	for (j, col) in enumerate(row):
		flag = 0
		for c in range(n):
			if a[i][c] == 1:
				flag = 1
				break
		if flag == 0:
			for r in range(m):
				if a[r][j] == 1:
					flag = 1
					break
		new_b[i][j] = flag
if new_b == b:
	print('YES')
	for row in a:
		for item in row:
			print(item, end=' ')
		print()
else:
	print('NO')


(m, n) = map(int, input().split())
l = []
for i in range(m):
	row = list(map(int, input().split()))
	l.append(row)
check = []
given = []
for i in range(m):
	check.append([1] * n)
	given.append([0] * n)
for i in range(m):
	for j in range(n):
		if l[i][j] == 0:
			for p in range(n):
				check[i][p] = 0
			for p in range(m):
				check[p][j] = 0
for i in range(m):
	for j in range(n):
		sum = 0
		for p in range(n):
			if check[i][p] == 1:
				sum = 1
				break
		if sum == 0:
			for p in range(m):
				if check[p][j] == 1:
					sum = 1
					break
		given[i][j] = sum
if l == given:
	print('YES')
	for i in check:
		for j in i:
			print(j, end=' ')
		print('\n')
else:
	print('NO')


(n, m) = [int(x) for x in input().split(' ')]
b = []
a = []
c = []
for i in range(n):
	b.append(input().split(' '))
	a.append(['1'] * m)
	c.append(['0'] * m)
for i in range(n):
	for j in range(m):
		if b[i][j] == '0':
			for k in range(n):
				a[k][j] = '0'
			for l in range(m):
				a[i][l] = '0'
for i in range(n):
	for j in range(m):
		if a[i][j] == '1':
			for k in range(n):
				c[k][j] = '1'
			for l in range(m):
				c[i][l] = '1'
if c == b:
	print('YES')
	for i in range(n):
		print(' '.join(a[i]))
else:
	print('NO')


(m, n) = map(int, input().split())
mat = []
for i in range(m):
	mat.append(list(map(int, input().split())))
y = [[1 for i in range(n)] for j in range(m)]
for i in range(m):
	for j in range(n):
		if mat[i][j] == 0:
			for x in range(m):
				y[x][j] = 0
			for x in range(n):
				y[i][x] = 0
for i in range(m):
	for j in range(n):
		tot = 0
		if mat[i][j] == 1:
			for x in range(m):
				tot += y[x][j]
			for x in range(n):
				tot += y[i][x]
			if tot == 0:
				print('NO')
				quit()
print('YES')
for i in y:
	print(' '.join(list(map(str, i))))


(r, c) = map(int, input().split())
matrix = []
original = [[0 for _ in range(c)] for _ in range(r)]
idex = 0
rowCheck = [0 for _ in range(r)]
columCheck = [0 for _ in range(c)]
ans = ['YES', 'NO']
for _ in range(r):
	matrix.append(list(map(int, input().split())))
put = 0
row = []
for i in range(r):
	if 0 not in matrix[i]:
		rowCheck[i] = 1
for j in range(c):
	start = 1
	for i in range(r):
		start &= matrix[i][j]
	if start == 1:
		columCheck[j] = 1
for i in range(r):
	if rowCheck[i]:
		for j in range(c):
			if columCheck[j]:
				original[i][j] = 1
rowCheck2 = [0 for _ in range(r)]
columCheck2 = [0 for _ in range(c)]
for i in range(r):
	if 1 in original[i]:
		rowCheck2[i] = 1
for j in range(c):
	start = 0
	for i in range(r):
		start |= original[i][j]
	if start == 1:
		columCheck2[j] = 1
for i in range(r):
	if idex:
		break
	for j in range(c):
		if matrix[i][j] != rowCheck2[i] | columCheck2[j]:
			idex = 1
if idex:
	print(ans[idex])
else:
	print(ans[idex])
	for v in original:
		print(*v)


(m, n) = map(int, input().split())
row = [True] * m
col = [True] * n
a = [[0] * n for _ in range(m)]
for i in range(m):
	s = list(map(int, input().split()))
	for j in range(n):
		if s[j] == 0:
			row[i] = False
			col[j] = False
		a[i][j] = s[j]
c = 0
r = 0
for i in range(n):
	if col[i]:
		c += 1
for j in range(m):
	if row[j]:
		r += 1
res = []
if r > 0 and c > 0 or (r == 0 and c == 0):
	for i in range(m):
		res.append([])
		for j in range(n):
			if col[j] and row[i]:
				res[i].append(1)
			elif a[i][j] == 0 or (col[j] or row[i]):
				res[i].append(0)
			else:
				print('NO')
				return
	print('YES')
	for i in range(m):
		s = ' '.join(list(map(str, res[i])))
		print(s)
else:
	print('NO')


def matrix_update(matrix, i, j):
	for row in range(len(matrix)):
		if row == i:
			matrix[i] = [0] * len(matrix[0])
			continue
		matrix[row][j] = 0
(m, n) = map(int, input().split())
matrix = []
ans = []
for _ in range(m):
	matrix.append(list(map(int, input().split(' '))))
	ans.append([1] * n)
for i in range(len(matrix)):
	for j in range(len(matrix[0])):
		if matrix[i][j]:
			continue
		else:
			matrix_update(ans, i, j)
flag = True
b = []
for i in range(len(ans)):
	row = []
	row_truth = any(ans[i])
	for j in range(len(ans[0])):
		row.append(any([row[j] for row in ans]) or row_truth)
	b.append(row)
if b == matrix:
	print('YES')
	for row in ans:
		for item in row:
			print(item, end=' ')
		print()
else:
	print('NO')


import sys
import math

def fn(m, n, k):
	a = [[1] * n] * m
	x = []
	y = []
	for i in range(m):
		for j in range(n):
			if k[i][j] == 0:
				a[i] = [0] * n
				x.append(j)
				continue
			else:
				y.append([i, j])
		continue
	y1 = [0] * len(y)
	for j in x:
		for i in range(m):
			a[i][j] = 0
	for i in y:
		if 1 in a[i[0]]:
			y1[y.index(i)] = 1
		else:
			for j in range(m):
				if a[j][i[1]] == 1:
					y1[y.index(i)] = 1
					break
	if 0 in y1:
		print('NO')
	else:
		print('YES')
		for row in a:
			print(*row)
input = sys.stdin.read()
data = list(map(int, input.split()))
m = data[0]
n = data[1]
k = [[0] * n] * m
l = 0
for i in range(m):
	k[i] = data[l + 2:l + 2 + n]
	l = l + n
fn(m, n, k)


(m, n) = map(int, input().split())
s = []
t = []
e = []
y = 0
z = 0
for i in range(m):
	d = list(map(int, input().split()))
	s.append(d)
	t.append([1] * len(d))
for i in range(len(s)):
	for j in range(len(s[i])):
		if s[i][j] == 0:
			t[i] = [0] * n
			for k in t:
				k[j] = 0
for i in range(m):
	q = []
	for j in range(n):
		p = t[i][j]
		for z in range(n):
			p = p or t[i][z]
		if p == 0:
			for v in range(m):
				p = p or t[v][j]
		q.append(p)
	e.append(q)
if e != s:
	print('NO')
else:
	print('YES')
	for i in t:
		for j in i:
			print(j, end=' ')
		else:
			print()


def main():
	(m, n) = [int(x) for x in input().split()]
	matrix = [[int(x) for x in input().split()] for i in range(m)]
	original = [[1 for i in range(n)] for j in range(m)]
	for row in range(m):
		for col in range(n):
			if matrix[row][col] == 0:
				for i in range(n):
					original[row][i] = 0
				for i in range(m):
					original[i][col] = 0
	for row in range(m):
		for col in range(n):
			if matrix[row][col] == 1:
				valid = False
				for i in range(n):
					if original[row][i] == 1:
						valid = True
						break
				for i in range(m):
					if original[i][col] == 1:
						valid = True
						break
				if valid == False:
					print('NO')
					return
	print('YES')
	for row in range(m):
		for col in range(n):
			print(original[row][col], end=' ')
		print()
	return
main()


from sys import stdin
(n, m) = map(int, stdin.readline().rstrip().split(' '))
l = []
for _ in range(n):
	al = list(map(int, stdin.readline().rstrip().split(' ')))
	l.append(al)
re = ' YES'
sol = [[0] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		if l[i][j] == 1:
			c1 = True
			c2 = True
			for k in range(n):
				if l[k][j] == 0:
					c1 = False
			for o in range(m):
				if l[i][o] == 0:
					c2 = False
			if c1 and c2:
				sol[i][j] = 1
			elif not c1 and (not c2):
				re = 'NO'
				break
if re == 'NO':
	print('NO')
else:
	test = [[0] * m for i in range(n)]
	for i in range(n):
		for j in range(m):
			if sol[i][j] == 1:
				for k in range(n):
					test[k][j] = 1
				for o in range(m):
					test[i][o] = 1
	if test == l:
		print('YES')
		for i in range(n):
			print(*sol[i])
	else:
		print('NO')


[M, N] = [int(s) for s in input().split()]
B = []
for i in range(M):
	row = [int(s) for s in input().split()]
	B.append(row)
A = [[1 for j in range(N)] for i in range(M)]
for i in range(M):
	for j in range(N):
		if B[i][j] == 0:
			A[i] = [0 for j in range(N)]
			for k in range(M):
				A[k][j] = 0
B1 = [[0 for j in range(N)] for i in range(M)]
for i in range(M):
	for j in range(N):
		if A[i][j] == 1:
			B1[i] = [1 for j in range(N)]
			for k in range(M):
				B1[k][j] = 1
if B != B1:
	print('NO')
else:
	print('YES')
	for i in range(M):
		print(' '.join(map(str, A[i])))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	(n, m) = LI()
	aa = [LI() for _ in range(n)]
	rr = []
	for i in range(n):
		r = []
		s = set(aa[i])
		for j in range(m):
			t = [0, 0]
			for k in range(n):
				t[aa[k][j]] += 1
			if t[0] == 0 and len(s) == 1:
				r.append(1)
			else:
				r.append(0)
		rr.append(r)
	bb = [[0] * m for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if rr[i][j] == 0:
				continue
			for k in range(n):
				bb[k][j] = 1
			for k in range(m):
				bb[i][k] = 1
	if bb != aa:
		return 'NO'
	return 'YES\n{}'.format('\n'.join(map(lambda x: ' '.join(map(str, x)), rr)))
print(main())


def or_matrix(B):
	m = len(B)
	n = len(B[0])
	A = [[1 for i in range(n)] for j in range(m)]
	C = [[0 for i in range(n)] for j in range(m)]
	s_r = set()
	s_c = set()
	for i in range(len(B)):
		for j in range(len(B[0])):
			if B[i][j] == 0:
				s_r.add(i)
				s_c.add(j)
	for i in range(len(A)):
		for j in range(len(A[0])):
			if i in s_r:
				A[i][j] = 0
			if j in s_c:
				A[i][j] = 0
	n_s_r = set()
	n_s_c = set()
	for i in range(len(A)):
		for j in range(len(A[0])):
			if A[i][j] == 1:
				n_s_r.add(i)
				n_s_c.add(j)
	for i in range(len(C)):
		for j in range(len(C[0])):
			if i in n_s_r:
				C[i][j] = 1
			if j in n_s_c:
				C[i][j] = 1
	if B == C:
		print('YES')
		for i in range(len(A)):
			for j in range(len(A[0])):
				print(A[i][j], end=' ')
			print()
	else:
		print('NO')
(m, n) = [int(x) for x in input().split()]
B = [[int(j) for j in input().split()] for i in range(m)]
or_matrix(B)


def find_matrix(s, matx):
	nbL = s[0]
	nbC = s[1]
	trouvee = [[1 for i in range(nbC)] for j in range(nbL)]
	recree = [[0 for i in range(nbC)] for j in range(nbL)]
	alreadychecked = [[False for i in range(nbC)] for j in range(nbL)]
	for l in range(nbL):
		for c in range(nbC):
			if matx[l][c] == 0:
				if not alreadychecked[l][c]:
					for l2 in range(nbL):
						trouvee[l2][c] = 0
					for c2 in range(nbC):
						trouvee[l][c2] = 0
						alreadychecked[l][c] = True
	for l in range(nbL):
		for c in range(nbC):
			if trouvee[l][c] == 1:
				for k in range(nbL):
					recree[k][c] = 1
				for k in range(nbC):
					recree[l][k] = 1
	if recree == matx:
		print('YES')
		for i in range(nbL):
			for j in range(nbC - 1):
				print(trouvee[i][j], end=' ')
			print(trouvee[i][nbC - 1])
	else:
		print('NO')
s = list(map(int, input().split()))
matx = [list(map(int, input().split())) for line in range(s[0])]
find_matrix(s, matx)


(n, m) = map(int, input().split())
a = []
b = [[0] * m for _ in range(n)]
for i in range(n):
	a.append(list())
	a[i].extend(map(int, input().split()))
c = list(zip(*a))
for i in range(n):
	if a[i].count(1) == len(a[i]):
		for j in range(m):
			if c[j].count(1) == len(c[j]):
				b[i][j] = 1
d = [[0] * m for _ in range(n)]
for i in range(n):
	for j in range(m):
		if b[i][j] == 1:
			for k in range(m):
				d[i][k] = 1
			for k in range(n):
				d[k][j] = 1
bol = 0
for i in range(n):
	for j in range(m):
		if a[i][j] != d[i][j]:
			bol = 1
if bol == 0:
	print('YES')
	for i in range(n):
		print(*b[i])
else:
	print('NO')


(m, n) = map(int, input().split())
B = [list(map(int, input().split())) for i in range(m)]
sr = [sum(B[i]) for i in range(m)]
sc = [sum([B[i][j] for i in range(m)]) for j in range(n)]
no = sum(sr) > 0 and (max(sr) < n or max(sc) < m)
for i in range(m):
	for j in range(n):
		if B[i][j] and sc[j] % m and sr[i] % n or no:
			print('NO')
			exit()
print('YES')
for i in range(m):
	Ai = [sr[i] // n * (sc[j] // m) for j in range(n)]
	print(' '.join((repr(a) for a in Ai)))


(m, n) = map(int, input().split())
b = []
c = 0
f = 0
for i in range(m):
	b.append(list(map(int, input().split())))
for i in range(m):
	for j in range(n):
		if b[i][j] == 0:
			c += 1
		else:
			f = 1
			break
	if f == 1:
		break
if c == m * n:
	print('YES')
	for i in range(m):
		print(*b[i])
	exit()
r = []
c = []
for i in range(m):
	if b[i][0] == 1:
		f = 0
		for j in range(n):
			if b[i][j] == 1:
				f += 1
		if f == n:
			r.append(i)
for i in range(n):
	if b[0][i] == 1:
		f = 0
		for j in range(m):
			if b[j][i] == 1:
				f += 1
		if f == m:
			c.append(i)
res = [[0] * n for i in range(m)]
res1 = [[0] * n for i in range(m)]
for i in r:
	for j in c:
		res[i][j] = 1
lr = []
lc = []
for i in range(m):
	for j in range(n):
		if res[i][j] == 1:
			lr.append(i)
			lc.append(j)
for i in lr:
	for j in range(n):
		res1[i][j] = 1
for j in lc:
	for i in range(m):
		res1[i][j] = 1
if res1 != b:
	print('NO')
else:
	print('YES')
	for i in range(m):
		for j in range(n):
			print(res[i][j], end=' ')
		print()


arr = [int(x) for x in input().split()]
(n, m) = (arr[0], arr[1])
arr = []
for i in range(n):
	li = [int(x) for x in input().split()]
	arr.append(li)
ans = [[1 for j in range(m)] for i in range(n)]
for i in range(n):
	for j in range(m):
		if arr[i][j] == 0:
			for k in range(m):
				ans[i][k] = 0
			for k in range(n):
				ans[k][j] = 0
ans1 = [[0 for j in range(m)] for i in range(n)]
for i in range(n):
	for j in range(m):
		if ans[i][j] == 1:
			ans1[i][j] = 1
for i in range(n):
	for j in range(m):
		if ans1[i][j] == 1:
			for k in range(m):
				if ans1[i][k] == 0:
					ans1[i][k] = -1
			for k in range(n):
				if ans1[k][j] == 0:
					ans1[k][j] = -1
for i in range(n):
	for j in range(m):
		if ans1[i][j] == -1:
			ans1[i][j] = 1
if ans1 == arr:
	print('YES')
	for i in range(n):
		print(*ans[i])
else:
	print('NO')


(m, n) = map(int, input().split())
a = [[1] * n] * m
c = [[0] * n] * m
b = []
for i in range(m):
	b.append(list(map(int, input().split())))
for i in range(0, m):
	for j in range(0, n):
		if b[i][j] == 0:
			a[i] = [0] * n
			for k in range(0, m):
				a[k][j] = 0
for i in range(m):
	for j in range(n):
		if a[i][j] == 1:
			c[i] = [1] * n
			for k in range(0, m):
				c[k][j] = 1
flag = 0
for i in range(m):
	for j in range(n):
		if b[i][j] != c[i][j]:
			flag = 1
			break
if flag == 1:
	print('NO')
else:
	print('YES')
	for i in range(m):
		for j in range(n):
			print(a[i][j], end=' ')
		print()


import operator

def mx_or(mx):
	n = len(mx)
	m = len(mx[0])
	result = [[0 for j in range(m)] for i in range(n)]
	for i in range(n):
		for j in range(m):
			if mx[i][j]:
				for k in range(n):
					result[k][j] = 1
				for k in range(m):
					result[i][k] = 1
	return result
none = lambda iterable: all(map(operator.not_, iterable))
(n, m) = map(int, input().split())
mx = [[] for i in range(n)]
for i in range(n):
	mx[i] = list(map(int, input().split()))
result = [[1 for j in range(m)] for i in range(n)]
for i in range(n):
	for j in range(m):
		if not mx[i][j]:
			for k in range(n):
				result[k][j] = 0
			for k in range(m):
				result[i][k] = 0
if mx_or(result) == mx:
	print('YES')
	for i in range(n):
		print(' '.join(map(str, result[i])))
else:
	print('NO')


__author__ = '-'
l1 = input().strip().split(' ')
m = int(l1[0])
n = int(l1[1])
B = []
for i in range(m):
	line = input().strip().split(' ')
	row = []
	for p in line:
		row.append(int(p))
	B.append(row)
A = [[0 for x in range(n)] for y in range(m)]

def transferA(B, m, n):
	A = [[0 for x in range(n)] for y in range(m)]
	for i in range(m):
		rida1 = True
		for j in range(n):
			if B[i][j] == 0:
				rida1 = False
				break
		if rida1:
			for j in range(n):
				veerg1 = True
				for r in range(m):
					if B[r][j] == 0:
						veerg1 = False
						break
				if veerg1 and rida1:
					A[i][j] = 1
	return A
A = transferA(B, m, n)

def transfer(A, m, n):
	C = [[0 for x in range(n)] for y in range(m)]
	for i in range(len(A)):
		for j in range(len(A[i])):
			if A[i][j] == 1:
				for k in range(n):
					C[i][k] = 1
				for l in range(m):
					C[l][j] = 1
	return C
C = transfer(A, m, n)
if C == B:
	print('YES')
	for i in range(len(A)):
		for j in range(len(A[i])):
			print(A[i][j], end=' ')
		print()
else:
	print('NO')


def getColumn(i):
	Temp = []
	for j in range(X[0]):
		Temp.append(Answer[j][i])
	return Temp

def setColumn(i):
	for j in range(X[0]):
		Answer[j][i] = 0

def setRow(i):
	for j in range(X[1]):
		Answer[i][j] = 0

def ShowMat():
	for i in range(X[0]):
		print(*Answer[i])
	print()
X = list(map(int, input().split()))
(Zeros, Ones) = ([], [])
S = [list(map(int, input().split())) for i in range(X[0])]
Answer = [[1] * X[1] for i in range(X[0])]
for i in range(X[0]):
	for j in range(X[1]):
		if S[i][j] == 0:
			Zeros.append([i, j])
		else:
			Ones.append([i, j])
for i in Zeros:
	setRow(i[0])
	setColumn(i[1])
for i in Ones:
	if 1 not in Answer[i[0]] + getColumn(i[1]):
		print('NO')
		exit()
print('YES')
ShowMat()


I = lambda : int(input())
IL = lambda : list(map(int, input().split()))
IF = lambda : list(map(float, input().split()))
(m, n) = IL()
B = [IL() for i in range(m)]
RS = [sum(b) == n for b in B]
CS = [sum((B[j][i] for j in range(m))) == m for i in range(n)]
A = [[rs * cs for cs in CS] for rs in RS]
B1 = [[0] * n for i in range(m)]
for i in range(m):
	for j in range(n):
		B1[i][j] = int(any(A[i]) or any((a[j] for a in A)))
if B == B1:
	print('YES')
	for a in A:
		print(*a)
else:
	print('NO')


def fn(a, i, j, m, n):
	(x, y) = (i, j)
	while x > 0:
		x -= 1
		if a[x][y] != 1:
			return 0
	(x, y) = (i, j)
	while x < m - 1:
		x += 1
		if a[x][y] != 1:
			return 0
	(x, y) = (i, j)
	while y > 0:
		y -= 1
		if a[x][y] != 1:
			return 0
	(x, y) = (i, j)
	while y < n - 1:
		y += 1
		if a[x][y] != 1:
			return 0
	return 1
(m, n) = map(int, input().split())
b = []
for i in range(m):
	p = list(map(int, input().split()))
	b.append(p[:])
d = []
for i in range(m):
	for j in range(n):
		if b[i][j] == 1:
			k = fn(b, i, j, m, n)
			if k == 1:
				d.append([i, j])
a = []
c = []
p = [0] * n
for i in range(m):
	a.append(p[:])
	c.append(p[:])
for (u, v) in d:
	a[u][v] = 1
	for i in range(m):
		c[i][v] = 1
	for j in range(n):
		c[u][j] = 1
f = 0
for i in range(m):
	for j in range(n):
		if c[i][j] != b[i][j]:
			f = 1
			break
if f == 1:
	print('NO')
else:
	print('YES')
	for i in range(m):
		print(*a[i])


(m, n) = list(map(int, input().rstrip().split()))
mat1 = []
mat2 = []
for i in range(m):
	mat1 += [list(map(int, input().rstrip().split()))]
	mat2 += [[1] * n]
for i in range(m):
	for j in range(n):
		if mat1[i][j] == 0:
			for x in range(m):
				mat2[x][j] = 0
			for y in range(n):
				mat2[i][y] = 0
flag = 1
for i in range(m):
	for j in range(n):
		if mat1[i][j] == 1:
			c = 0
			for x in range(m):
				if mat2[x][j] == 1:
					c += 1
			for y in range(n):
				if mat2[i][y] == 1:
					c += 1
			if c == 0:
				flag = 0
				break
if flag == 0:
	print('NO')
else:
	print('YES')
	for i in range(m):
		print(*mat2[i])


(m, n) = map(int, input().split())
possible_row = [True for _ in range(m)]
possible_column = [True for _ in range(n)]
B = [None for _ in range(m)]
for i in range(m):
	B[i] = list(map(int, input().split()))
for i in range(m):
	for j in range(n):
		if B[i][j] is 0:
			possible_row[i] = False
			possible_column[j] = False
flag = False
for i in range(m):
	for j in range(n):
		if B[i][j] is 1 and (not possible_row[i] and (not possible_column[j])):
			flag = True
for i in range(m):
	if possible_row[i]:
		flag1 = False
		for j in range(n):
			if possible_column[j]:
				flag1 = True
		if not flag1:
			flag = True
for i in range(n):
	if possible_column[i]:
		flag1 = False
		for j in range(m):
			if possible_row[j]:
				flag1 = True
		if not flag1:
			flag = True
if flag:
	print('NO')
else:
	print('YES')
	for i in range(m):
		for j in range(n):
			if possible_column[j] and possible_row[i]:
				print(1, end=' ')
			else:
				print(0, end=' ')
		print()


read = lambda : map(int, input().split())
(n, m) = read()
a = [list(read()) for i in range(n)]
pi = [1] * m
pj = [1] * n
ai = []
aj = []
flag = 0
for i in range(n):
	if a[i] == pi:
		ai.append(i)
	else:
		for j in range(m):
			if a[i][j] and [a[k][j] for k in range(n)] != pj:
				print('NO')
				exit()
			elif a[i][j]:
				aj.append(j)
f1 = ai == [] or aj == []
f2 = not (ai == [] and aj == [])
f3 = a == [pi for i in range(n)]
if f1 and f2 and (not f3):
	print('NO')
	exit()
print('YES')
A = [[0] * m for i in range(n)]
if not f3:
	for i in ai:
		for j in aj:
			A[i][j] = 1
else:
	A = a
[print(*i) for i in A]


(a, b) = map(int, input().split(' '))
array = [[1] * b for i in range(a)]
orig = [list(map(int, input().split(' '))) for i in range(a)]
matrix = []
for i in orig:
	matrix.append(i[:])
row0 = []
col0 = []
for i in range(a):
	for j in range(b):
		if matrix[i][j] == 0:
			row0.append(i)
			col0.append(j)
row0 = list(set(row0))
col0 = list(set(col0))
for i in row0:
	matrix[i] = [0] * b
for ele in col0:
	for i in range(a):
		matrix[i][ele] = 0
match = [[0] * b for i in range(a)]
for i in range(len(matrix)):
	if 1 in matrix[i]:
		match[i] = [1] * len(matrix[0])
jlist = []
for i in range(a):
	for j in range(b):
		if matrix[i][j] == 1:
			jlist.append(j)
for i in jlist:
	for bad in range(len(match)):
		match[bad][i] = 1
if match == orig:
	print('YES')
	for i in matrix:
		print(' '.join([str(j) for j in i]))
else:
	print('NO')


string = input()
numbers = string.split()
(a, b) = (int(numbers[0]), int(numbers[1]))
ma = [[1 for x in range(b)] for y in range(a)]
mb = []
for x in range(a):
	string = input()
	mb.append(list(map(int, string.split())))
for x in range(a):
	for y in range(b):
		if mb[x][y] == 0:
			for z in range(b):
				ma[x][z] = 0
			for z in range(a):
				ma[z][y] = 0
results = 'YES'
for x in range(a):
	for y in range(b):
		if mb[x][y] == 1:
			for z in range(b):
				if ma[x][z]:
					break
			else:
				results = 'NO'
			if results == 'NO':
				for z in range(a):
					if ma[z][y]:
						results = 'YES'
						break
				else:
					results = 'NO'
					break
	if results == 'NO':
		break
print(results)
if results == 'YES':
	for x in ma:
		print(' '.join(map(str, x)))


try:
	(m, n) = map(int, input().split())
	B = [list(map(int, input().split())) for i in range(m)]
	srows = [sum(B[i]) for i in range(m)]
	scol = [sum([B[i][j] for i in range(m)]) for j in range(n)]
	for i in range(m):
		if srows[i] > 0 and srows[i] < n:
			for j in range(n):
				if B[i][j] and scol[j] > 0 and (scol[j] < m):
					print('NO')
					exit()
	if sum(srows) > 0 and (max(srows) < n or max(scol) < m):
		print('NO')
	else:
		print('YES')
		for i in range(m):
			Ai = [1 if srows[i] == n and scol[j] == m else 0 for j in range(n)]
			print(' '.join((repr(a) for a in Ai)))
except:
	pass


(r, c) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(r)]
ans = []
sum_row = [sum(a[i]) for i in range(r)]
sum_col = [sum((a[i][j] for i in range(r))) for j in range(c)]
no = sum(sum_row) > 0 and (max(sum_row) < c or max(sum_col) < r)
for i in range(r):
	for j in range(c):
		if a[i][j] and sum_row[i] < c and (sum_col[j] < r) or no:
			print('NO')
			exit()
print('YES')
ans = [[sum_row[i] // c * (sum_col[j] // r) for j in range(c)] for i in range(r)]
for i in range(r):
	print(*ans[i])


import sys
import string
import math
from collections import defaultdict
from functools import lru_cache
from collections import Counter

def mi(s):
	return map(int, s.strip().split())

def lmi(s):
	return list(mi(s))

def tmi(s):
	return tuple(mi(s))

def mf(f, s):
	return map(f, s)

def lmf(f, s):
	return list(mf(f, s))

def js(lst):
	return ' '.join((str(d) for d in lst))

def line():
	return sys.stdin.readline().strip()

def linesp():
	return line().split()

def iline():
	return int(line())

def mat(n):
	matr = []
	for _ in range(n):
		matr.append(linesp())
	return matr

def mati(n):
	mat = []
	for _ in range(n):
		mat.append(lmi(line()))
	return mat

def pmat(mat):
	for row in mat:
		print(js(row))

def dist(x, y):
	return ((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) ** 0.5

def fast_exp(x, n):
	if n == 0:
		return 1
	elif n % 2 == 1:
		return x * fast_exp(x, (n - 1) // 2) ** 2
	else:
		return fast_exp(x, n // 2) ** 2

def main(mat):
	z_col = set()
	z_row = set()
	for i in range(len(mat)):
		for j in range(len(mat[i])):
			if mat[i][j] == 0:
				z_row.add(i)
				z_col.add(j)
	ans = [[0 for _ in range(len(mat[i]))] for i in range(len(mat))]
	row_done = set()
	col_done = set()
	pending_row = set()
	pending_col = set()
	for i in range(len(mat)):
		for j in range(len(mat[i])):
			if mat[i][j] == 1:
				if i not in z_row and j not in z_col:
					ans[i][j] = 1
					row_done.add(i)
					col_done.add(j)
					if i in pending_row:
						pending_row.remove(i)
					if j in pending_col:
						pending_col.remove(j)
				elif i not in z_row and j in z_col:
					if i not in row_done:
						pending_row.add(i)
				elif i in z_row and j not in z_col:
					if j not in col_done:
						pending_col.add(j)
				else:
					print('NO')
					return
	for i in pending_row:
		done = False
		for j in range(len(mat[i])):
			if j not in z_col:
				ans[i][j] = 1
				if j in pending_col:
					pending_col.remove(j)
				done = True
		if not done:
			print('NO')
			return
	for j in pending_col:
		done = False
		for i in range(len(mat)):
			if i not in z_row:
				ans[i][j] = 1
				done = True
		if not done:
			print('NO')
			return
	print('YES')
	pmat(ans)
(n, _) = mi(line())
mat = mati(n)
main(mat)


(m, n) = map(int, input().split())
d = {}
for i in range(m):
	l = list(map(int, input().split()))
	for j in range(n):
		d[i, j] = l[j]
row_1 = [r for r in range(m) if all([d[r, c] == 1 for c in range(n)])]
col_1 = [c for c in range(n) if all([d[r, c] == 1 for r in range(m)])]
if (len(row_1) > 0) ^ (len(col_1) > 0):
	print('NO')
else:
	for (i, j) in d:
		if d[i, j] == 1 and (not (i in row_1 or j in col_1)):
			print('NO')
			break
	else:
		print('YES')
		result = [[0 for i in range(n)] for j in range(m)]
		for i in row_1:
			for j in col_1:
				result[i][j] = 1
		for i in range(m):
			for j in range(n):
				print(result[i][j], end=' ')
			print()


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


def solve(n, m, b):
	a = [[1 for i in range(m)] for i in range(n)]
	for i in range(n):
		for j in range(m):
			if b[i][j] == 0:
				for k in range(m):
					a[i][k] = 0
				for k in range(n):
					a[k][j] = 0
	for i in range(n):
		for j in range(m):
			temp = 0
			for k in range(m):
				temp |= a[i][k]
			for k in range(n):
				temp |= a[k][j]
			if temp != b[i][j]:
				return (False, a)
	return (True, a)
(n, m) = map(int, input().split())
b = []
for i in range(n):
	row = list(map(int, input().split()))
	b.append(row.copy())
(possible, a) = solve(n, m, b)
if possible:
	print('YES')
	for i in range(n):
		print(' '.join(map(str, a[i])))
else:
	print('NO')


(n, m) = input().split(' ')
(n, m) = (int(n), int(m))
(a, b) = ([], [])
for i in range(n):
	l = input().split(' ')
	b.append([int(i) for i in l])
	l = [-1 for i in range(m)]
	a.append(l)
for i in range(n):
	for j in range(m):
		if b[i][j] == 0:
			for c in range(m):
				a[i][c] = 0
			for d in range(n):
				a[d][j] = 0
done = 0
for i in range(n):
	for j in range(m):
		if b[i][j] == 1:
			for c in range(m):
				if a[i][c] == -1 or a[i][c] == 1:
					done += 1
					a[i][c] = 1
			for d in range(n):
				if a[d][j] == -1 or a[d][j] == 1:
					done += 1
					a[d][j] = 1
			if done == 0:
				done = -1
				break
			else:
				done = 0
	if done == -1:
		break
if done == -1:
	print('NO')
else:
	print('YES')
	for i in a:
		for j in i:
			print(j, end=' ')
		print()


def findVal(arr, i, j, m, n):
	val = 1
	for k in range(n):
		val = val * arr[i][k]
	for k in range(m):
		val = val * arr[k][j]
	return val

def recoverVal(arr, i, j, m, n):
	val = 0
	for k in range(n):
		val = val + arr[i][k]
	for k in range(m):
		val = val + arr[k][j]
	if val > 0:
		val = 1
	return val
(m, n) = map(int, input().strip().split())
arr = [[0 for i in range(n)] for j in range(m)]
arrNew = [[0 for i in range(n)] for j in range(m)]
recoverArr = [[0 for i in range(n)] for j in range(m)]
for i in range(m):
	tempArr = list(map(int, input().split()))[:n]
	for j in range(n):
		arr[i][j] = tempArr[j]
for i in range(m):
	for j in range(n):
		arrNew[i][j] = findVal(arr, i, j, m, n)
for i in range(m):
	for j in range(n):
		recoverArr[i][j] = recoverVal(arrNew, i, j, m, n)
if arr == recoverArr:
	print('YES')
	for i in range(m):
		for j in range(n):
			print(arrNew[i][j], end=' ')
		print()
else:
	print('NO')


(n, m) = [int(i) for i in input().split()]
sum1 = [0] * n
sum2 = [0] * m
res = [[0] * m for i in range(n)]
a = 0
k = [0] * 4
flag = False
for i in range(n):
	a = [int(i2) for i2 in input().split()]
	sum1[i] = sum(a)
	for i2 in range(m):
		sum2[i2] += a[i2]
for i in range(n):
	if sum1[i] == m:
		k[2] += 1
for i in range(m):
	if sum2[i] == n:
		k[3] += 1
for i in range(n):
	if sum1[i] > k[3] and (not (sum1[i] == 0 or sum1[i] == m)) or (k[2] * k[3] == 0 and k[2] != k[3]):
		flag = True
for i in range(m):
	if sum2[i] > k[2] and (not (sum2[i] == 0 or sum2[i] == n)) or (k[2] * k[3] == 0 and k[2] != k[3]):
		flag = True
if flag:
	print('NO')
else:
	print('YES')
	for i in range(n):
		for i2 in range(m):
			res[i][i2] = 1
	for i in range(m):
		if sum2[i] != n:
			for i2 in range(n):
				res[i2][i] = 0
	for i in range(n):
		if sum1[i] != m:
			for i2 in range(m):
				res[i][i2] = 0
	for i in range(n):
		for i2 in range(m):
			print(res[i][i2], end=' ')
		print()


(m, n) = map(int, input().split(' '))
matrix = []
for _ in range(m):
	matrix.append([int(x) for x in input().split(' ')])
a = [0 for i in range(m)]
b = [0 for j in range(n)]
for i in range(m):
	p = 1
	for j in range(n):
		p = p & matrix[i][j]
	a[i] = p
for j in range(n):
	p = 1
	for i in range(m):
		p = p & matrix[i][j]
	b[j] = p
f1 = 0
f2 = 0
f3 = 0
for i in range(m):
	for j in range(n):
		if matrix[i][j] == 1:
			if a[i] == 0 and b[j] == 0:
				f1 = 1
				break
			if f3 == 0:
				f3 = 1
		if a[i] == 1 and b[j] == 1:
			if f2 == 0:
				f2 = 1
			matrix[i][j] = '1 '
		else:
			matrix[i][j] = '0 '
	if f1 == 1:
		break
if f1 == 0 and f2 ^ f3 == 0:
	print('YES')
	for i in matrix:
		print(''.join(i))
else:
	print('NO')


(n, m) = map(int, input().split())
l = [[0] for i in range(n)]
l1 = [[1 for j in range(m)] for i in range(n)]
for i in range(n):
	l2 = list(map(int, input().split()))
	l[i] = l2
t = 0
for i in range(n):
	for j in range(m):
		z = l[i][j]
		if z == 1:
			pass
		else:
			for k in range(n):
				l1[k][j] = 0
			for k in range(m):
				l1[i][k] = 0
for i in range(n):
	for j in range(m):
		z = 0
		for k in range(n):
			if l1[k][j] == 1:
				z = 1
				break
			else:
				pass
		for k in range(m):
			if l1[i][k] == 1:
				z = 1
				break
			else:
				pass
		if l[i][j] == z:
			pass
		else:
			t = 1
			break
if t == 1:
	print('NO')
else:
	print('YES')
	for i in range(n):
		for j in range(m):
			print(l1[i][j], end=' ')
		print()


(m, n) = map(int, input().split())
a = []
for i in range(m):
	q = []
	for j in range(n):
		q.append(1)
	a.append(q)
p = []
for i in range(m):
	arr = list(map(int, input().split()))
	p.append(arr)
for i in range(m):
	for j in range(n):
		if p[i][j] == 0:
			for l in range(m):
				a[l][j] = 0
			for k in range(n):
				a[i][k] = 0
f = []
for i in range(m):
	c = []
	for j in range(n):
		c.append(a[i][j])
	f.append(c)
for i in range(m):
	for j in range(n):
		if f[i][j] == 1:
			for l in range(m):
				a[l][j] = 1
			for k in range(n):
				a[i][k] = 1
if a == p:
	print('YES')
	for i in range(m):
		for j in range(n):
			print(f[i][j], end=' ')
		print()
else:
	print('NO')


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


(r, c) = map(int, input().split())
matrix = [0] * r
(row_zero, col_zero) = (set(), set())
for i in range(r):
	row = map(int, input().split())
	matrix[i] = list(row)
for (i, row) in enumerate(matrix):
	for (j, elem) in enumerate(row):
		if elem == 0:
			row_zero.add(i)
			col_zero.add(j)
mid_matrix = [[1] * c for i in range(r)]
(row_ones, col_ones) = (set(), set())
for (i, row) in enumerate(mid_matrix):
	for (j, elem) in enumerate(row):
		if i in row_zero:
			mid_matrix[i][j] = 0
		if j in col_zero:
			mid_matrix[i][j] = 0
		if mid_matrix[i][j] == 1:
			row_ones.add(i)
			col_ones.add(j)
final_matrix = [[None] * c for i in range(r)]
for (i, row) in enumerate(final_matrix):
	for (j, elem) in enumerate(row):
		if i in row_ones:
			final_matrix[i][j] = 1
		if j in col_ones:
			final_matrix[i][j] = 1
		if not final_matrix[i][j]:
			final_matrix[i][j] = 0
if matrix == final_matrix:
	print('YES')
	for (i, row) in enumerate(mid_matrix):
		row = map(str, row)
		print(' '.join(row))
else:
	print('NO')


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def solve():
	(n, m) = mi()
	r = [1] * n
	c = [1] * m
	a = []
	for i in range(n):
		a.append(li())
	for i in range(n):
		for j in range(m):
			r[i] &= a[i][j]
			c[j] &= a[i][j]
	x = [[0] * m for i in range(n)]
	for i in range(n):
		for j in range(m):
			x[i][j] = r[i] & c[j]
	r = [0] * n
	c = [0] * m
	for i in range(n):
		for j in range(m):
			r[i] |= x[i][j]
			c[j] |= x[i][j]
	f = 0
	for i in range(n):
		for j in range(m):
			if a[i][j] == 1:
				if c[j] == 0 and r[i] == 0:
					print('NO')
					exit(0)
	print('YES')
	for i in range(n):
		print(*x[i])
solve()


def matrix_print(mat):
	print('\n'.join(map(lambda line: ' '.join(map(str, line)), mat)))

def matrix_sum(mat):
	return sum(list(map(sum, mat)))

def main():
	(m, n) = map(int, input().split())
	b = []
	for _ in range(m):
		line = list(map(int, input().split()))
		b.append(line)
	a = [[1] * n] * m
	for i in range(m):
		for j in range(n):
			if b[i][j] == 0:
				a[i] = [0] * n
				for e in range(m):
					a[e][j] = 0
	for i in range(m):
		for j in range(n):
			if a[i][j] == 1:
				for e in range(m):
					b[e][j] = 0
				b[i] = [0] * n
	if matrix_sum(b) > 0:
		print('NO')
	else:
		print('YES')
		matrix_print(a)
main()


(m, n) = map(int, input().split())
arr = [list(map(int, input().split())) for i in range(m)]
sum_row = [sum(arr[i]) for i in range(m)]
sum_col = [sum([arr[i][j] for i in range(m)]) for j in range(n)]
invalid = sum(sum_row) > 0 and (max(sum_row) < n or max(sum_col) < m)
for i in range(m):
	for j in range(n):
		if arr[i][j] > 0 and sum_col[j] % m != 0 and (sum_row[i] % n != 0) or invalid:
			print('NO')
			exit()
print('YES')
for i in range(m):
	res = [sum_row[i] // n * (sum_col[j] // m) for j in range(n)]
	print(*res)


(n, m) = map(int, input().split())
b = []
a = [m * [1] for _ in range(n)]
for i in range(n):
	b += [list(map(int, input().split()))]
	for k in range(m):
		if b[i][k] == 0:
			a[i] = m * [0]
			for j in range(n):
				a[j][k] = 0
stop = 0
i = 0
while not stop and i < n:
	for j in range(m):
		s = 0
		for k in range(n):
			s += a[k][j]
		if b[i][j] != min(1, s + sum(a[i])):
			stop = 1
			break
	i += 1
if stop:
	print('NO')
else:
	print('YES')
	for i in range(n):
		print(*a[i])


nums = input().split()
(rows, colums) = (int(nums[0]), int(nums[1]))
matrix1 = [[1] * colums] * rows
inputMatrix = []
for _ in range(rows):
	inputMatrix.append([int(i) for i in input().split()])
for (rowIndex, row) in enumerate(inputMatrix):
	for (columIndex, val) in enumerate(row):
		if val == 0:
			matrix1[rowIndex] = [0] * colums
			for j in range(rows):
				matrix1[j][columIndex] = 0

def check():
	for (rowIndex, row) in enumerate(inputMatrix):
		for (columIndex, val) in enumerate(row):
			if val == 1:
				dic = []
				for j in range(rows):
					dic.append(matrix1[j][columIndex])
				if 1 not in matrix1[rowIndex] and 1 not in dic:
					return 'NO'
	return 'YES'
checkVal = check()
if checkVal == 'NO':
	print('NO')
else:
	print('YES')
	for row in matrix1:
		print(' '.join((str(x) for x in row)))


(m, n) = list(map(int, input().split()))
b = [list(map(int, input().split())) for _ in range(m)]
b_t = list(zip(*b))
elem = set()
rows = set()
cols = set()
possible = True
row = 0
while row < m and possible:
	col = 0
	while col < n:
		element = b[row][col]
		elem.add(element)
		if element == 1:
			if not all((b[row][i] == 1 for i in range(n))) and (not all((b_t[col][i] == 1 for i in range(m)))):
				possible = False
				break
			if all((b[row][i] == 1 for i in range(n))):
				rows.add(row)
			if all((b_t[col][i] == 1 for i in range(m))):
				cols.add(col)
		col += 1
	row += 1
if not possible:
	print('NO')
elif (len(rows) == 0 or len(cols) == 0) and len(elem) == 2:
	print('NO')
else:
	print('YES')
	out = []
	for row in range(m):
		curr_row = []
		for col in range(n):
			if col in cols and row in rows:
				curr_row.append('1')
			else:
				curr_row.append('0')
		out.append(curr_row)
	for row in out:
		print(' '.join(row))


from math import *
import sys
input = sys.stdin.readline
global flag

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

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

def ma():
	return map(int, input().split())
t = 1
while t:
	t -= 1
	r = []
	(n, m) = ma()
	for i in range(n):
		r.append(lis())
	ro = [0] * n
	co = [0] * m
	fl = 0
	for i in range(n):
		for j in range(m):
			if r[i][j] == 0:
				ro[i] = 1
				co[j] = 1
	for i in range(n):
		for j in range(m):
			if r[i][j] == 1:
				if ro[i] and co[j]:
					fl = 1
					break
	res = [[0 for i in range(m)] for j in range(n)]
	for i in range(n):
		for j in range(m):
			if ro[i] == 0 and co[j] == 0:
				res[i][j] = 1
	rco = [0] * n
	cco = [0] * m
	res1 = [x[:] for x in res]
	for i in range(n):
		for j in range(m):
			if res[i][j]:
				rco[i] = 1
				cco[j] = 1
	for i in range(n):
		if rco[i]:
			for k in range(m):
				res[i][k] = 1
	for i in range(m):
		if cco[i]:
			for k in range(n):
				res[k][i] = 1
	for i in range(n):
		for j in range(m):
			if res[i][j] != r[i][j]:
				fl = 1
				break
	if fl:
		print('NO')
	else:
		print('YES')
		for i in res1:
			print(*i)


from collections import Counter
import string
import math

def array_int():
	return [int(i) for i in input().split()]

def vary(number_of_variables):
	if number_of_variables == 1:
		return int(input())
	if number_of_variables >= 2:
		return map(int, input().split())

def makedict(var):
	return dict(Counter(var))
mod = 1000000007
(m, n) = vary(2)
mat = []
for i in range(m):
	mat.append(array_int())
pat = []
for i in range(m):
	pat.append([int(-2) for j in range(n)])
for i in range(m):
	for j in range(n):
		if mat[i][j] == 0:
			for k in range(n):
				pat[i][k] = 0
			for k in range(m):
				pat[k][j] = 0
for i in range(m):
	for j in range(n):
		if pat[i][j] == -2:
			pat[i][j] = 1
cat = []
for i in range(m):
	cat.append([0 for j in range(n)])
for i in range(m):
	for j in range(n):
		for k in range(n):
			if pat[i][k] == 1:
				cat[i][j] = 1
		for k in range(m):
			if pat[k][j] == 1:
				cat[i][j] = 1
if cat == mat:
	print('YES')
	for i in range(m):
		print(*pat[i])
else:
	print('NO')


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

def main():
	(n, m) = input_ints()
	b = []
	for i in range(n):
		b.append(input_ints())
	r = [False] * n
	c = [False] * m
	for i in range(n):
		r[i] = all(b[i])
	for j in range(m):
		c[j] = all([b[i][j] for i in range(n)])
	a = []
	r2 = [False] * n
	c2 = [False] * m
	for i in range(n):
		tmp = []
		for j in range(m):
			if r[i] and c[j]:
				tmp.append(1)
				r2[i] = True
				c2[j] = True
			else:
				tmp.append(0)
		a.append(tmp)
	for i in range(n):
		for j in range(m):
			if b[i][j] and (not r2[i] and (not c2[j])):
				print('NO')
				return
	print('YES')
	for i in range(n):
		print(' '.join([str(x) for x in a[i]]))
main()


def transform(a, n, m):
	row = [False for i in range(n)]
	col = [False for i in range(m)]
	mat = [[True for i in range(m)] for j in range(n)]
	for i in range(n):
		for j in range(m):
			if a[i][j] == False:
				row[i] = True
				col[j] = True
	for i in range(n):
		for j in range(m):
			if row[i] == True or col[j] == True:
				mat[i][j] = False
	return mat

def isvlid(inp, mat, m, n):
	row = [False for i in range(n)]
	col = [False for i in range(m)]
	newinp = [[False for i in range(m)] for j in range(n)]
	for i in range(n):
		for j in range(m):
			if mat[i][j] == True:
				row[i] = True
				col[j] = True
	for i in range(n):
		for j in range(m):
			if row[i] == True or col[j] == True:
				newinp[i][j] = True
	for i in range(n):
		for j in range(m):
			if inp[i][j] != newinp[i][j]:
				return False
	return True
line = input()
lst = line.split()
n = int(lst[0])
m = int(lst[1])
inp = [[False for i in range(m)] for j in range(n)]
for i in range(n):
	line = input()
	lst = line.split()
	for j in range(m):
		inp[i][j] = True if int(lst[j]) == 1 else False
mat = transform(inp, n, m)
if isvlid(inp, mat, m, n):
	print('YES')
	for i in range(n):
		for j in range(m):
			if mat[i][j]:
				print('1', end=' ')
			else:
				print('0', end=' ')
		print()
else:
	print('NO')


(m, n) = map(int, input().split())
B = [list(map(int, input().split())) for x in range(m)]
A = [[1 for x in range(n)] for x in range(m)]
for i in range(m):
	for j in range(n):
		if B[i][j] == 0:
			for y in range(m):
				A[y][j] = 0
			for z in range(n):
				A[i][z] = 0
for i in range(m):
	for j in range(n):
		tmp = 0
		for y in range(m):
			tmp = tmp | A[y][j]
		for z in range(n):
			tmp = tmp | A[i][z]
		if tmp != B[i][j]:
			print('NO')
			exit()
print('YES')
for li in A:
	print(' '.join(map(str, li)))


(m, n) = (int(x) for x in input().split())
b = []
r1 = []
for i in range(m):
	b.append([int(x) for x in input().split()])
	r1.append(sum(b[i]) == n)
c1 = [sum((b[i][j] for i in range(m))) == m for j in range(n)]
if (sum(r1) == 0 and sum(c1)) != 0 or (sum(r1) != 0 and sum(c1) == 0):
	print('NO')
	exit()
a = []
for i in range(m):
	a.append([])
	for j in range(n):
		if b[i][j] == 0:
			a[i].append(0)
		elif not r1[i] and (not c1[j]):
			print('NO')
			exit()
		else:
			a[i].append(1 if r1[i] and c1[j] else 0)
print('YES')
for i in range(m):
	print(' '.join(map(str, a[i])))


(n, m) = [int(x) for x in input().split()]
arr = []
for _ in range(n):
	arr.append([int(x) for x in input().split()])
ans = [[1 for k in range(m)] for i in range(n)]
(r, c) = (set(), set())
for i in range(n):
	for j in range(m):
		if arr[i][j] == 0:
			r.add(i)
			c.add(j)
flag = True
for j in range(n):
	for i in range(m):
		if arr[j][i] == 1 and (j in r and i in c or len(r) == n or len(c) == m):
			flag = False
		if j in r or i in c:
			ans[j][i] = 0
if flag == False:
	print('NO')
else:
	print('YES')
	for i in ans:
		for j in i:
			print(j, end=' ')
		print()


def readline():
	return [int(c) for c in input().split()]

def or_in_matrix(matrix, n, m):
	res = [[-1] * m for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == 0:
				for ii in range(n):
					res[ii][j] = 0
				for jj in range(m):
					res[i][jj] = 0
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == 1:
				cnt = 0
				for ii in range(n):
					if res[ii][j] == 1:
						cnt += 1
					elif res[ii][j] == -1:
						res[ii][j] = 1
						cnt += 1
				for jj in range(m):
					if res[i][jj] == 1:
						cnt += 1
					elif res[i][jj] == -1:
						res[i][jj] = 1
						cnt += 1
				if cnt == 0:
					return False
	return res

def main():
	(n, m) = readline()
	matrix = []
	for _ in range(n):
		matrix.append(readline())
	ans = or_in_matrix(matrix, n, m)
	if ans:
		print('YES')
		for e in ans:
			print(*e)
	else:
		print('NO')
main()


from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
(n, m) = M()
a = []
for _ in range(n):
	b = LI()
	a += [b]
b = []
for _ in range(n):
	b += [[1] * m]
for i in range(n):
	for j in range(m):
		if a[i][j] == 0:
			for k in range(m):
				b[i][k] = 0
			for k in range(n):
				b[k][j] = 0
flag = 1
for i in range(n):
	for j in range(m):
		if a[i][j] == 0:
			if sum(b[i]) >= 1:
				flag = 0
				break
			else:
				for k in range(n):
					if b[k][j] == 1:
						flag = 0
						break
		elif sum(b[i]) >= 1:
			continue
		else:
			for k in range(n):
				if b[k][j] == 1:
					flag = 0
					break
			if not flag:
				flag = 1
			else:
				flag = 0
				break
	if not flag:
		break
if flag:
	print('YES')
	for i in range(n):
		print(*b[i])
else:
	print('NO')


(m, n) = list(map(int, input().split()))
B = [list(map(int, input().split())) for i in range(m)]
sr = [sum(B[i]) for i in range(m)]
sc = [sum([B[i][j] for i in range(m)]) for j in range(n)]
for i in range(m):
	if sr[i] > 0 and sr[i] < n:
		for j in range(n):
			if B[i][j] and sc[j] > 0 and (sc[j] < m):
				print('NO')
				return
if sum(sr) > 0 and (max(sr) < n or max(sc) < m):
	print('NO')
else:
	print('YES')
	for i in range(m):
		Ai = [1 if sr[i] == n and sc[j] == m else 0 for j in range(n)]
		print(' '.join((repr(a) for a in Ai)))


(m, n) = map(int, input().split())
b = []
for i in range(m):
	b.append(list(map(int, input().split())))
a = [[1] * n] * m
sett = set()
for i in range(m):
	for j in range(n):
		if b[i][j] == 0:
			a[i][j] = 0
			sett.add(i)
s = list(sett)
for i in s:
	a[i] = [0] * n
b1 = [[0] * n] * m
sett = set()
for i in range(m):
	for j in range(n):
		if a[i][j] == 1:
			b1[i][j] = 1
			sett.add(i)
s = list(sett)
for i in s:
	b1[i] = [1] * n
if b == b1:
	print('YES')
	for i in range(m):
		print(*a[i])
else:
	print('NO')


def main():

	def parser():
		while 1:
			data = list(input().split(' '))
			for number in data:
				if len(number) > 0:
					yield number
	input_parser = parser()
	gets = lambda : next(input_parser)

	def getNum():
		data = gets()
		try:
			return int(data)
		except ValueError:
			return float(data)
	(n, m) = (getNum(), getNum())
	RANGN = range(n)
	RANGM = range(m)
	b = [[] for _ in RANGN]
	a = [[1 for _ in RANGM] for _ in RANGN]
	for y in RANGN:
		for x in RANGM:
			v = getNum()
			b[y].append(v)
			if v == 0:
				for i in RANGM:
					a[y][i] = 0
				for i in RANGN:
					a[i][x] = 0
	for y in RANGN:
		for x in RANGM:
			ror = any(a[y]) or any({a[i][x] for i in RANGN})
			if ror != b[y][x]:
				print('NO')
				return
	print('YES')
	for y in RANGN:
		for x in RANGM:
			print(a[y][x], end=' \n'[x == m - 1])
main()


(n, m) = map(int, input().split())
d = []
for i in range(n):
	c = list(map(int, input().split()))
	d.append(c)
flag = True
a = []
for i in range(n):
	c = []
	for j in range(m):
		c.append(1)
	a.append(c)
for i in range(n):
	for j in range(m):
		if d[i][j] == 0:
			for k in range(0, n):
				a[k][j] = 0
			for k in range(0, m):
				a[i][k] = 0
e = []
for i in range(n):
	c = []
	for j in range(m):
		c.append(0)
	e.append(c)
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			for k in range(0, n):
				e[k][j] = 1
			for k in range(0, m):
				e[i][k] = 1
if e == d:
	print('YES')
	for i in a:
		print(*i)
else:
	print('NO')


def solve(a, b, c, m, n):
	for i in range(m):
		for j in range(n):
			if b[i][j] == 0:
				for k in range(n):
					a[i][k] = 0
				for k in range(m):
					a[k][j] = 0
	for i in range(m):
		for j in range(n):
			if a[i][j]:
				for k in range(n):
					c[i][k] = 1
				for k in range(m):
					c[k][j] = 1
	for i in range(m):
		for j in range(n):
			if c[i][j] != b[i][j]:
				return False
	return True
(m, n) = map(int, input().split())
b = []
for i in range(m):
	x = [int(i) for i in input().split()]
	b.append(x)
a = [[1 for i in range(n)] for i in range(m)]
c = [[0 for i in range(n)] for i in range(m)]
ans = solve(a, b, c, m, n)
if ans == True:
	print('YES')
	for i in range(len(a)):
		print(*a[i])
else:
	print('NO')


(n, m) = map(int, input().split())
a = [[0 for x in range(0, 200)] for x in range(0, 200)]
for i in range(0, n):
	b = input()
	a[i] = b.split(' ')
for i in range(0, n):
	for j in range(0, m):
		a[i][j] = int(a[i][j])
ans = [[1 for x in range(0, 200)] for x in range(0, 200)]
for i in range(0, n):
	for j in range(0, m):
		if a[i][j] == 0:
			for i1 in range(0, n):
				ans[i1][j] = 0
			for j1 in range(0, m):
				ans[i][j1] = 0
b = [[1 for x in range(0, 200)] for x in range(0, 200)]
for i in range(0, n):
	for j in range(0, m):
		b[i][j] = 0
		for j1 in range(0, m):
			b[i][j] = b[i][j] | ans[i][j1]
		for i1 in range(0, n):
			b[i][j] = b[i][j] | ans[i1][j]
		if b[i][j] != a[i][j]:
			print('NO')
			exit(0)
print('YES')
for i in range(0, n):
	res = ''
	for j in range(0, m):
		res = res + str(ans[i][j])
		res = res + ' '
	print(res)


a = []
b = []
t = input().split(' ')
n = int(t[0])
m = int(t[1])
for i in range(n):
	c = []
	b.append(c)
	c = []
	a.append(c)
	x = input().split(' ')
	for j in range(m):
		b[i].append(int(x[j]))
		a[i].append(1)
for i in range(n):
	for j in range(m):
		if b[i][j] == 0:
			for k in range(n):
				a[k][j] = 0
			for k in range(m):
				a[i][k] = 0
ok = 1
for i in range(n):
	for j in range(m):
		if b[i][j] == 1:
			s = 0
			for k in range(n):
				s = s or a[k][j]
			for k in range(m):
				s = s or a[i][k]
			if s == 0:
				ok = 0
if ok == 0:
	print('NO')
else:
	print('YES')
	for i in range(n):
		for j in range(m):
			print('%d ' % a[i][j], end='')
		print('')


(n, m) = map(int, input().split())
lis = []
ans = [[0] * m for i in range(n)]
for i in range(n):
	a = list(map(int, input().split()))
	lis.append(a)
for i in range(n):
	c = lis[i].count(1)
	if c == m:
		for j in range(m):
			ans[i][j] = 1
for j in range(m):
	c = 0
	for i in range(n):
		if lis[i][j] == 1:
			c += 1
	if c == n:
		for i in range(n):
			ans[i][j] += 1
for i in range(n):
	for j in range(m):
		if ans[i][j] == 2:
			for k in range(m):
				if ans[i][k] != 2:
					ans[i][k] = 0
				lis[i][k] = 0
			for k in range(n):
				if ans[k][j] != 2:
					ans[k][j] = 0
				lis[k][j] = 0
for i in lis:
	if 1 in i:
		print('NO')
		exit()
if 1 > 0:
	print('YES')
	for i in ans:
		for j in i:
			if j == 2:
				print(1, end=' ')
			else:
				print(0, end=' ')
		print()


(r, c) = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(r)]
r_count = [0 for _ in range(r)]
c_count = [0 for _ in range(c)]
for (i, r_) in enumerate(grid):
	r_count[i] = r_.count(1)
	for (j, c_) in enumerate(r_):
		if c_ == 1:
			c_count[j] += 1
out = [[0 for _ in range(c)] for row in range(r)]
entry = False
for x in range(r):
	for y in range(c):
		if r_count[x] == c and c_count[y] == r:
			out[x][y] = '1'
			entry = True
		elif grid[x][y] == 1 and (r_count[x] != c and c_count[y] != r):
			print('NO')
			exit()
		else:
			out[x][y] = '0'
if not entry and sum(r_count) + sum(c_count) > 0:
	print('NO')
	exit()
print('YES')
print('\n'.join([' '.join(x) for x in out]))


def main():
	(m, n) = [int(i) for i in input().split()]
	b = [[int(i) for i in input().split()] for i in range(m)]
	a = [[1 for _ in range(n)] for _ in range(m)]
	for bi in range(m):
		for bj in range(n):
			if b[bi][bj] == 1:
				continue
			for j in range(n):
				a[bi][j] = 0
			for i in range(m):
				a[i][bj] = 0
	valid = True
	for ai in range(m):
		for aj in range(n):
			status = False
			for j in range(n):
				if a[ai][j] == 1:
					status = True
			for i in range(m):
				if a[i][aj] == 1:
					status = True
			if status:
				if b[ai][aj] != 1:
					valid = False
			elif b[ai][aj] != 0:
				valid = False
	if valid:
		print('YES')
		for row in a:
			print(*row)
	else:
		print('NO')
main()


import sys
(m, n) = map(int, input().split())
oneUps = [0 for _ in range(n)]
oneRights = [0 for _ in range(m)]
zeroUps = set()
zeroRights = set()
B = []
cnt = 0
for i in range(m):
	row = list(map(int, input().split()))
	B.append(row)
	for j in range(n):
		if row[j] == 1:
			oneUps[j] += 1
			oneRights[i] += 1
			cnt += 1
		else:
			zeroUps.add(j)
			zeroRights.add(i)
Ones = set()
i = 0
j = 0
for i in range(m):
	for j in range(n):
		if oneUps[j] == m and oneRights[i] == n:
			Ones.add((i, j))
grid = [[None for _ in range(n)] for _ in range(m)]
i = 0
j = 0
result = True
for i in range(m):
	for j in range(n):
		if (i, j) in Ones:
			if B[i][j] == 0:
				result = False
			grid[i][j] = 1
		if i in zeroRights or j in zeroUps:
			grid[i][j] = 0
		if (i, j) in Ones and (i in zeroRights or j in zeroUps):
			result = False
		if B[i][j] == 1:
			if not oneUps[j] == m and (not oneRights[i] == n):
				result = False
i = 0
j = 0
if len(Ones) == 0 and cnt >= 1:
	print('NO')
elif result:
	print('YES')
	for i in range(m):
		print(' '.join(map(str, grid[i])))
else:
	print('NO')


def cont(d, i, j, e):
	if e in d[i]:
		return True
	for k in d:
		if k[j] == e:
			return True
	return False
(n, m) = map(int, input().split())
d = []
t = []
for i in range(n):
	d.append(list(map(int, input().split())))
	t.append([1] * m)
for i in range(n):
	for j in range(m):
		if d[i][j] == 0:
			t[i] = [0] * m
			for k in range(n):
				t[k][j] = 0
for i in range(n):
	for j in range(m):
		if d[i][j] == 1 and (not cont(t, i, j, 1)):
			print('NO')
			exit()
print('YES')
for i in t:
	[print(j, end=' ') for j in i]
	print()


(m, n) = map(int, input().split())
a = []
for _ in range(m):
	a.append(list(map(int, input().split())))
r1 = [1] * m
r2 = [0] * m
c1 = [1] * n
c2 = [0] * n
possible = True
for i in range(m):
	for j in range(n):
		if a[i][j] == 0:
			r1[i] = 0
			c1[j] = 0
for i in range(m):
	for j in range(n):
		if r1[i] and c1[j]:
			r2[i] = 1
			c2[j] = 1
for i in range(m):
	for j in range(n):
		if (r2[i] or c2[j]) != a[i][j]:
			possible = False
			break
	if not possible:
		break
if possible:
	print('YES')
	for i in range(m):
		for j in range(n):
			print('1' if r1[i] and c1[j] else '0', end=' ')
		print()
else:
	print('NO')


(n, m) = map(int, input().split())
arr = [list(map(int, input().split())) for row in range(n)]
A = [[1 for col in range(m)] for row in range(n)]
for row in range(n):
	for col in range(m):
		if arr[row][col] == 0:
			A[row] = [0 for x in range(m)]
			for x in range(n):
				A[x][col] = 0
for row in range(n):
	for col in range(m):
		if arr[row][col] == 1:
			if sum(A[row]) == 0 and sum([x[col] for x in A]) == 0:
				print('NO')
				exit()
print('YES')
for row in range(n):
	print(' '.join((str(x) for x in A[row])))


(n, k) = [int(x) for x in input().split()]
arr = []
ans = []
rows = [0] * n
cols = [0] * k
for i in range(n):
	arr.append(input().split())
	ans.append(['0'] * k)
	rows[i] = all(map(lambda a: a == '1', arr[-1]))
for i in range(k):
	sum = 0
	for j in range(n):
		sum += 1 if arr[j][i] == '1' else 0
	if sum == n:
		cols[i] = True
for i in range(n):
	for j in range(k):
		if arr[i][j] == '1' and (not rows[i]) and (not cols[j]) or (arr[i][j] == '0' and (rows[i] or cols[j])):
			print('NO')
			exit()
if any(rows) ^ any(cols):
	print('NO')
	exit()
for i in range(n):
	if not rows[i]:
		continue
	for j in range(k):
		if cols[j]:
			ans[i][j] = '1'
print('YES')
print('\n'.join((' '.join(l) for l in ans)))


(m, n) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
p = [[1 for _ in range(n)] for _ in range(m)]
e = [[0 for _ in range(n)] for _ in range(m)]
for r in range(m):
	if 0 in a[r]:
		for i in range(n):
			p[r][i] = 0
for c in range(n):
	if 0 in [e[c] for e in a]:
		for i in range(m):
			p[i][c] = 0
for r in range(m):
	if 1 in p[r]:
		for i in range(n):
			e[r][i] = 1
for c in range(n):
	if 1 in [e[c] for e in p]:
		for i in range(m):
			e[i][c] = 1
if a == e:
	print('YES')
	for e in p:
		print(' '.join(map(str, e)))
else:
	print('NO')


(n, m) = map(int, input().split())
mat = []
for _ in range(n):
	row = list(map(int, input().split()))
	mat.append(row)
arr = [[-1 for _ in range(m)] for _ in range(n)]
for i in range(n):
	for j in range(m):
		if mat[i][j] == 0:
			for k in range(m):
				arr[i][k] = 0
			for k in range(n):
				arr[k][j] = 0
res = True
for i in range(n):
	for j in range(m):
		ans = False
		if mat[i][j] == 1:
			for k in range(m):
				if arr[i][k] == -1:
					ans = True
					break
			for k in range(n):
				if arr[k][j] == -1:
					ans = True
					break
			if not ans:
				res = False
				break
	if not res:
		break
if res:
	print('YES')
	for i in arr:
		for j in i:
			if j == -1:
				print(1, end=' ')
			else:
				print(j, end=' ')
		print()
else:
	print('NO')


def check(a, b, m, n):
	for i in range(m):
		for j in range(n):
			k = 0
			for x in range(m):
				k |= a[x][j]
			for x in range(n):
				k |= a[i][x]
			if k != b[i][j]:
				return False
	return True
input_values = lambda : [int(x) for x in input().split()]
(m, n) = input_values()
b = []
for i in range(m):
	b.append(input_values())
a = [[1 for j in range(n)] for i in range(m)]
for i in range(m):
	for j in range(n):
		if b[i][j] == 0:
			for x in range(m):
				a[x][j] = 0
			for x in range(n):
				a[i][x] = 0
if check(a, b, m, n):
	print('YES')
	for i in range(m):
		print(' '.join([str(x) for x in a[i]]))
else:
	print('NO')


import sys
(m, n) = map(int, sys.stdin.readline().split())
mat = []
ans = []
for i in range(m):
	a = list(map(int, sys.stdin.readline().split()))
	mat.append(a)
	ans.append([-1] * n)
for i in range(m):
	for j in range(n):
		if mat[i][j] == 0:
			for k in range(n):
				ans[i][k] = 0
			for k in range(m):
				ans[k][j] = 0
for i in range(m):
	for j in range(n):
		if ans[i][j] == -1:
			ans[i][j] = 1
row = [0] * m
col = [0] * n
for i in range(m):
	for j in range(n):
		row[i] |= ans[i][j]
for i in range(n):
	for j in range(m):
		col[i] |= ans[j][i]
has = True
for i in range(m):
	for j in range(n):
		if mat[i][j] != row[i] | col[j]:
			has = False
			break
	if has == False:
		break
if has == False:
	print('NO')
else:
	print('YES')
	for i in range(m):
		print(' '.join(map(str, ans[i])))
	print()


def main():
	(n, m) = map(int, input().split(' '))
	B = []
	for i in range(n):
		B.append(list(map(int, input().split(' '))))
	r = []
	c = []
	for i in range(n):
		if len(list(filter(lambda x: x == 1, B[i]))) == len(B[i]):
			r.append(1)
		else:
			r.append(0)
	for j in range(m):
		col = [B[i][j] for i in range(n)]
		if len(list(filter(lambda x: x == 1, col))) == len(col):
			c.append(1)
		else:
			c.append(0)
	A = [[-1 for i in range(m)] for j in range(n)]
	yes = True
	for i in range(n):
		for j in range(m):
			if r[i] == 1 and c[j] == 1:
				A[i][j] = 1
			else:
				A[i][j] = 0
	for i in range(n):
		for j in range(m):
			o = 0
			for k in range(n):
				o |= A[k][j]
			for k in range(m):
				o |= A[i][k]
			if o != B[i][j]:
				print('NO')
				return
	print('YES')
	for i in range(n):
		print(' '.join(list(map(str, A[i]))))
main()


(m, n) = map(int, input().split())
l = []
ind = []
out = [[1] * n for i in range(m)]

def check(b):
	for i in range(m):
		if out[i][b] == 1:
			return True
	return False
for i in range(m):
	k = list(map(int, input().split()))
	for j in range(len(k)):
		if k[j] == 0:
			for h in range(m):
				out[h][j] = 0
			for t in range(n):
				out[i][t] = 0
		if k[j] == 1:
			ind.append((i, j))
flag = True
for i in ind:
	if 1 in out[i[0]] or check(i[1]):
		pass
	else:
		print('NO')
		flag = False
		break
if flag:
	print('YES')
	for i in range(m):
		for j in range(n):
			print(out[i][j], end=' ')
		print()


import sys
from math import *
import threading
from itertools import count
from pprint import pprint
from collections import defaultdict
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(300000)
mod = 10 ** 9 + 7
inf = 10 ** 15
decision = ['NO', 'YES']
yes = 'YES'
no = 'NO'
import os
from io import BytesIO, IOBase
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')

def npr(n, r):
	return factorial(n) // factorial(n - r) if n >= r else 0

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	li = []
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, len(prime)):
		if prime[p]:
			li.append(p)
	return li

def primefactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n //= 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n //= i
	if n > 2:
		factors.append(n)
	return factors

def prod(li):
	ans = 1
	for i in li:
		ans *= i
	return ans
for _ in range(1):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append(list(map(int, input().split())))
	(x, y) = ([], [])
	for i in range(n):
		for j in range(m):
			if a[i][j] == 0:
				x.append(i)
				y.append(j)
	b = [[1 for j in range(m)] for i in range(n)]
	for i in x:
		for j in range(m):
			b[i][j] = 0
	for i in y:
		for j in range(n):
			b[j][i] = 0
	(x, y) = ([], [])
	for i in range(n):
		for j in range(m):
			if b[i][j] == 1:
				x.append(i)
				y.append(j)
	temp = [[0 for j in range(m)] for i in range(n)]
	for i in x:
		for j in range(m):
			temp[i][j] = 1
	for i in y:
		for j in range(n):
			temp[j][i] = 1
	f = 1
	for i in range(n):
		for j in range(m):
			if temp[i][j] != a[i][j]:
				f = 0
				break
	if f:
		print(yes)
		for i in range(n):
			print(*b[i])
	else:
		print(no)


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

def ANDrow(grid, i):
	ans = 1
	for j in range(n):
		ans = ans and grid[i][j]
	return ans

def ANDcol(grid, j):
	ans = 1
	for i in range(m):
		ans = ans and grid[i][j]
	return ans
gridA = []
for i in range(m):
	temp = []
	for j in range(n):
		temp.append(0)
	gridA.append(temp)
flag = True
countR = 0
countC = 0
for i in range(m):
	if not flag:
		break
	for j in range(n):
		androw = ANDrow(grid[:], i)
		countR += androw
		andcol = ANDcol(grid[:], j)
		countC += andcol
		gridA[i][j] = int(bool(grid[i][j]) and bool(androw) and bool(andcol))
		flag2 = grid[i][j] and (not (androw or andcol))
		if flag2:
			flag = False
			break
if flag and (not (countC == 0) ^ (countR == 0)):
	print('YES')
	for i in gridA:
		print(*i)
else:
	print('NO')


flag = 0
flg_one = 0
zeros = []
ones = []
import sys
(n, m) = map(int, input().split())
lst = [[]] * n
for i in range(n):
	x = list(map(int, input().split()))
	if 0 in x:
		lst[i] = [0] * m
		for u in range(m):
			if x[u] == 1:
				flag = 1
				ones.append(u)
			else:
				zeros.append(u)
	else:
		lst[i] = [1] * m
		flg_one = 1
ones = list(set(ones))
zeros = list(set(zeros))
if flag == 1 and flg_one == 0 or (flg_one == 1 and len(zeros) == m):
	print('NO')
else:
	for q in range(n):
		if lst[q][0] == 1:
			for p in range(len(zeros)):
				lst[q][zeros[p]] = 0
	for i in range(len(ones)):
		co = 0
		for h in range(n):
			if lst[h][ones[i]] != 1:
				co += 1
		if co == n:
			print('NO')
			sys.exit(0)
	print('YES')
	for i in range(n):
		print(*lst[i])


(m, n) = list(map(int, input().split(' ')))
a = []
b = []
for i in range(m):
	a.append([1 for i in range(n)])
for i in range(m):
	b.append([int(y) for y in input().split()])
for i in range(m):
	for j in range(n):
		if b[i][j] == 0:
			for k in range(m):
				a[k][j] = 0
			for z in range(n):
				a[i][z] = 0
finalmatrix = []
for i in range(m):
	finalmatrix.append([0 for i in range(n)])
for i in range(m):
	for j in range(n):
		rvalue = 0
		cvalue = 0
		for k in range(m):
			rvalue = rvalue or a[k][j]
		for z in range(n):
			cvalue = cvalue or a[i][z]
		finalmatrix[i][j] = cvalue or rvalue
flag = True
for i in range(m):
	for j in range(n):
		if finalmatrix[i][j] != b[i][j]:
			flag = False
			break
if flag:
	print('YES')
	for i in range(m):
		for j in range(n):
			print(a[i][j], end=' ')
		print(end='\n')
else:
	print('NO')


from sys import stdin, stdout
from collections import Counter

def no_mistake(m, n, A, B):
	for i in range(m):
		for j in range(n):
			if B[i][j] == 1:
				flag = False
				if A[i].__contains__(1):
					flag = True
					continue
				else:
					for k in range(m):
						if A[k][j] == 1:
							flag = True
							break
				if not flag:
					return False
	return True

def format_output_list(alist):
	res = ''
	for element in alist:
		res += str(element) + ' '
	res = res.strip()
	res += '\n'
	return res

def format_matrix(m, n, A):
	res = ''
	for alist in A:
		res += format_output_list(alist)
	return res

def solve(m, n, B):
	A = [[1] * n] * m
	for i in range(m):
		for j in range(n):
			if B[i][j] == 0:
				A[i] = [0] * n
				for k in range(m):
					A[k][j] = 0
	if no_mistake(m, n, A, B):
		return 'YES\n' + format_matrix(m, n, A)
	return 'NO'
(m, n) = list(map(int, stdin.readline().rstrip().split()))
count = m
matrix = []
while count > 0:
	count -= 1
	matrix.append(list(map(int, stdin.readline().rstrip().split())))
stdout.write(str(solve(m, n, matrix)))


from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest
from math import ceil, floor, log, log2, sqrt, gcd, factorial, pow, pi
from bisect import bisect_left, bisect_right

def binNumber(n, size=4):
	return bin(n)[2:].zfill(size)

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

def ini():
	return int(input())

def isp():
	return map(int, input().split())

def sti():
	return str(input())

def par(a):
	print(' '.join(list(map(str, a))))

def tdl(outerListSize, innerListSize, defaultValue=0):
	return [[defaultValue] * innerListSize for i in range(outerListSize)]

def sts(s):
	s = list(s)
	s.sort()
	return ''.join(s)

class pair:

	def __init__(self, f, s):
		self.fi = f
		self.se = s

	def __lt__(self, other):
		return (self.fi, self.se) < (other.fi, other.se)

def check(a):
	s = a[0][0] + a[1][0] + a[2][0]
	for i in range(3):
		if sum(a[i]) != s:
			return False
	for i in range(3):
		s1 = 0
		for j in range(3):
			s1 += a[i][j]
		if s1 != s:
			return False
	s1 = a[1][1] + a[2][2] + a[0][0]
	s2 = a[2][0] + a[1][1] + a[0][2]
	if s1 != s or s2 != s:
		return False
	return True
(n, m) = isp()
a = tdl(n, m, 1)
b = tdl(n, m)
b1 = tdl(n, m)
r = [0] * n
c = [0] * m
for i in range(n):
	b[i] = iar()
for i in range(n):
	for j in range(m):
		if b[i][j] == 0:
			a[i] = [0] * m
			for k in range(n):
				a[k][j] = 0
for i in range(n):
	for j in range(m):
		r[i] = r[i] or a[i][j]
for i in range(m):
	for j in range(n):
		c[i] = c[i] or a[j][i]
for i in range(n):
	for j in range(m):
		b1[i][j] = r[i] or c[j]
if b1 == b:
	print('YES')
	for i in range(n):
		print(' '.join(list(map(str, a[i]))))
else:
	print('NO')


(n, m) = map(int, input().split())
rows0 = set()
cols0 = set()
row_col1 = []
for i in range(n):
	p = input().split()
	for j in range(m):
		if p[j] == '0':
			rows0.add(i)
			cols0.add(j)
		else:
			row_col1.append([i, j])
if len(list(rows0)) == n and row_col1 != [] or (len(list(cols0)) == m and row_col1 != []):
	print('NO')
	exit()
for k in row_col1:
	if k[0] in rows0 and k[1] in cols0:
		print('NO')
		exit()
print('YES')
all0 = ['0' for _ in range(m)]
all1 = ['1' for _ in range(m)]
matrixA = []
for i in range(n):
	if i in rows0:
		matrixA.append(all0)
	else:
		matrixA.append(all1)
for j in cols0:
	for i in range(n):
		matrixA[i][j] = '0'
for i in matrixA:
	print(*i)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')

def value():
	return map(int, input().split())

def array():
	return [int(i) for i in input().split()]
(r, c) = value()
m = []
for i in range(r):
	m.append(array())
row = defaultdict(int)
col = defaultdict(int)
for i in range(r):
	for j in range(c):
		if m[i][j] == 0:
			row[i] = 1
			col[j] = 1
ans = []
for i in range(r):
	ans.append([])
	if row[i] == 1:
		ans[i] = [0] * c
	else:
		for j in range(c):
			if col[j] == 1:
				ans[i].append(0)
			else:
				ans[i].append(1)
f = 1
for i in range(r):
	x = sum(ans[i])
	for j in range(c):
		y = 0
		for k in range(r):
			y += ans[k][j]
		if x + y > 0 and m[i][j] == 0:
			f = 0
			break
		elif m[i][j] == 1 and x + y == 0:
			f = 0
			break
if f == 1:
	print('YES')
	for i in ans:
		print(*i)
else:
	print('NO')


import math, sys
from collections import defaultdict, Counter, deque
from functools import reduce
INF = float('inf')
MOD = int(1000000000.0) + 7

def solve():
	(n, m) = vars()
	mat = []
	for i in range(n):
		mat.append(array())
	row = [1] * n
	col = [1] * m
	for i in range(n):
		for j in range(m):
			if not mat[i][j]:
				row[i] = 0
				col[j] = 0
	if bool(sum(row)) ^ bool(sum(col)):
		print('NO')
		return
	for i in range(n):
		for j in range(m):
			if mat[i][j]:
				if row[i] or col[j]:
					mat[i][j] = int(row[i] and col[j])
				else:
					print('NO')
					return
	print('YES')
	for r in mat:
		print(*r)

def main():
	t = 1
	for _ in range(t):
		solve()

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

class DSU:

	def __init__(self, n):
		self.p = [i for i in range(n + 1)]
		self.size = [1 for i in range(n + 1)]
		self.minmax = [[i, i] for i in range(n + 1)]
		self.n = n

	def find(self, node):
		if self.p[node] != node:
			self.p[node] = self.find(self.p[node])
		return self.p[node]

	def union(self, source, dest):
		source = self.find(source)
		dest = self.find(dest)
		if source != dest:
			if self.size[source] < self.size[dest]:
				(source, dest) = (dest, source)
			self.p[dest] = source
			self.size[source] += self.size[dest]
			mini = min(self.minmax[source][0], self.minmax[dest][0])
			maxi = max(self.minmax[source][1], self.minmax[dest][1])
			self.minmax[source] = [mini, maxi]

def input():
	return sys.stdin.readline().rstrip('\n')

def print(*args, sep=' ', end='\n'):
	first = True
	for arg in args:
		if not first:
			sys.stdout.write(sep)
		sys.stdout.write(str(arg))
		first = False
	sys.stdout.write(end)

def vars():
	return map(int, input().split())

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


(n, m) = map(int, input().split())
b = []
for i in range(n):
	b.append(list(map(int, input().split())))
a = [[1 for i in range(m)] for i in range(n)]
(row, col) = (set(), set())
for i in range(n):
	for j in range(m):
		if b[i][j] == 0:
			row.add(i)
			col.add(j)
for r in row:
	for i in range(m):
		a[r][i] = 0
for c in col:
	for i in range(n):
		a[i][c] = 0
gFlag = True
for i in range(n):
	for j in range(m):
		if b[i][j] == 1:
			valid = False
			for k in range(m):
				if a[i][k] == 1:
					valid = True
					break
			for k in range(n):
				if a[k][j] == 1:
					valid = True
					break
			if not valid:
				gFlag = False
				break
		else:
			valid = True
			for k in range(m):
				if a[i][k] == 1:
					valid = False
					break
			for k in range(n):
				if a[k][j] == 1:
					valid = False
					break
			if not valid:
				gFlag = False
				break
	if not gFlag:
		break
if not gFlag:
	print('NO')
else:
	print('YES')
	for i in range(n):
		for j in range(m):
			print(a[i][j], end=' ')
		print()


def OrMat():
	(M, N) = input().split()
	m = int(M)
	n = int(N)
	A = []
	for _ in range(m):
		ip_arr = [int(i) for i in input().split(' ')]
		A.append(ip_arr)
	B = []
	for _ in range(m):
		temp = []
		for _ in range(n):
			temp.append(-1)
		B.append(temp)
	for i in range(m):
		for j in range(n):
			p = i
			q = 0
			while q < n:
				if A[p][q] == 0:
					B[i][j] = 0
				q += 1
			p = 0
			q = j
			while p < m:
				if A[p][q] == 0:
					B[i][j] = 0
				p += 1
			if B[i][j] == -1:
				B[i][j] = 1
			else:
				B[i][j] = 0
	res = 0
	for i in range(m):
		for j in range(n):
			p = i
			q = 0
			while q < n:
				res = res or B[p][q]
				q += 1
			p = 0
			q = j
			while p < m:
				res = res or B[p][q]
				p += 1
			if A[i][j] != res:
				print('NO')
				return
			else:
				res = 0
	print('YES')
	for i in B:
		for j in i:
			print(j, end=' ')
		print(end='\n')
OrMat()


def arr_inp():
	return [int(x) for x in stdin.readline().split()]

def fill_mem():
	for i in range(m):
		for j in range(n):
			if mat[i][j] == 0:
				(row[i], col[j]) = (1, 1)

def valid():
	(r, c) = (0, 0)
	for i in row.values():
		if i:
			r += 1
	for i in col.values():
		if i:
			c += 1
	for i in range(m):
		for j in range(n):
			if mat[i][j]:
				if r == m or c == n:
					exit(print('NO'))
				if col[j] and row[i]:
					exit(print('NO'))

def print_ans():
	print('YES')
	for i in range(m):
		for j in range(n):
			if not row[i] and (not col[j]):
				print(1, end=' ')
			else:
				print(0, end=' ')
		print(end='\n')
from sys import stdin
from collections import defaultdict
(m, n) = arr_inp()
(mat, row, col) = ([arr_inp() for i in range(m)], defaultdict(int), defaultdict(int))
fill_mem()
valid()
print_ans()


import math, sys
from collections import defaultdict, deque
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

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

def In():
	return map(int, sys.stdin.readline().split())

def Sn():
	return sys.stdin.readline().strip()

def Pr(x):
	sys.stdout.write(str(x) + '\n')

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gte(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(n, m) = In()
		l = [list(In()) for i in range(n)]
		dp = [[0 for i in range(m)] for j in range(n)]
		ok = True
		for i in range(n):
			for j in range(m):
				if l[i][j] == 1:
					(hor, ver) = (0, 0)
					for k in range(m):
						if l[i][k] == 1:
							hor += 1
					for k in range(n):
						if l[k][j] == 1:
							ver += 1
					if ver != n and hor != m:
						ok = False
					elif ver == n and hor == m:
						dp[i][j] = 1
		check = [[0 for i in range(m)] for j in range(n)]
		for i in range(n):
			for j in range(m):
				t1 = 0
				for k in range(m):
					t1 |= dp[i][k]
				for k in range(n):
					t1 |= dp[k][j]
				if t1 != l[i][j]:
					ok = False
		if not ok:
			no()
		else:
			yes()
			for x in dp:
				print(*x)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


(m, n) = map(int, input().split())
b = []
a = []
temp = []
for i in range(m):
	b.append(list(map(int, input().split())))
	a.append([1] * n)
	temp.append([0] * n)

def fn(i, j, a):
	for k in range(n):
		a[i][k] = 0
	for l in range(m):
		a[l][j] = 0
	return a

def fn1(i, j, temp):
	for k in range(n):
		temp[i][k] = 1
	for l in range(m):
		temp[l][j] = 1
	return temp
for i in range(m):
	for j in range(n):
		if b[i][j] == 0:
			a = fn(i, j, a)
for i in range(m):
	for j in range(n):
		if a[i][j] == 1:
			temp = fn1(i, j, temp)
if temp == b:
	print('YES')
	for i in range(m):
		print('  '.join((str(x) for x in a[i])))
else:
	print('NO')


(n, m) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
(I, J) = ([0] * n, [0] * m)
(IS, JS) = ([0] * n, [0] * m)
(CountI, CountJ) = (0, 0)
for i in range(n):
	IS[i] = sum(A[i])
	if IS[i] == m:
		I[i] = 1
		CountI += 1
for j in range(m):
	JS[j] = sum([A[i][j] for i in range(n)])
	if JS[j] == n:
		J[j] = 1
		CountJ += 1
flag = True
i = 0
while i < n and flag:
	if IS[i] != m and IS[i] != CountJ:
		flag = False
	i += 1
j = 0
while j < m and flag:
	if JS[j] != n and JS[j] != CountI:
		flag = False
	j += 1
if flag and (not (sum(I) + sum(J) > 0 and sum(I) * sum(J) == 0)):
	print('YES')
	for i in range(n):
		for j in range(m):
			print(I[i] * J[j], end=' ')
		print()
else:
	print('NO')


def zip_sorted(a, b):
	(a, b) = zip(*sorted(zip(a, b)))
	sorted(zip(a, b), key=lambda x: x[1])
	return (a, b)

def column(matrix, i):
	return [row[i] for row in matrix]
(m, n) = [int(n1) for n1 in input().split()]
b = []
for i in range(m):
	a = [int(n1) for n1 in input().split()]
	b.append(a)
c = [[1 for x in range(n)] for y in range(m)]
d = [1] * m
e = [1] * n
d1 = [0] * m
e1 = [0] * n
count = 0
for i in range(len(b)):
	for j in range(len(b[i])):
		if b[i][j] == 0:
			d[i] = 0
			e[j] = 0
if count >= 1 and sum(d) + sum(e) == 0:
	print('NO')
else:
	for i in range(len(c)):
		for j in range(len(c[i])):
			if d[i] == 1 and e[j] == 1:
				c[i][j] = 1
			else:
				c[i][j] = 0
	count = 0
	for i in range(len(c)):
		for j in range(len(c[i])):
			if b[i][j] == 1:
				if 1 in c[i] or 1 in column(c, j):
					pass
				else:
					count = 1
					break
		if count == 1:
			break
	if count == 0:
		if sum(sum(c, [])) == 0 and count >= 1:
			print('NO')
		else:
			print('YES')
			for i in range(len(c)):
				print(*c[i])
	else:
		print('NO')


l1 = [int(x) for x in input().split()]
n = l1[0]
m = l1[1]
l2 = []
l3 = []
for i in range(0, n):
	l4 = [int(x) for x in input().split()]
	l2.append(l4)
	li = []
	for i in range(0, m):
		li.append(1)
	l3.append(li)
for i in range(0, n):
	for j in range(0, m):
		if l2[i][j] == 0:
			for k in range(0, m):
				l3[i][k] = 0
			for k in range(0, n):
				l3[k][j] = 0
check = 0
for i in range(0, n):
	for j in range(0, m):
		val = 0
		for k in range(0, m):
			val = val or l3[i][k]
			if val == 1:
				break
		for k in range(0, n):
			val = val or l3[k][j]
			if val == 1:
				break
		if val != l2[i][j]:
			check = 1
			break
	if check == 1:
		print('NO')
		break
if check == 0:
	print('YES')
	for i in range(0, n):
		for j in range(0, m):
			print(l3[i][j], end=' ')
		print()


(m, n) = map(int, input().split())
b = []
a = []
for i in range(m):
	b.append(list(map(int, input().split())))
	a.append([1] * n)
for i in range(m):
	for j in range(n):
		if b[i][j] == 0:
			for i1 in range(m):
				a[i1][j] = 0
			for j1 in range(n):
				a[i][j1] = 0
for i in range(m):
	for j in range(n):
		v = 0
		for i1 in range(m):
			v = v or a[i1][j]
		for j1 in range(n):
			v = v or a[i][j1]
		if bool(v) != bool(b[i][j]):
			print('NO')
			exit()
print('YES')
for i in range(m):
	print(' '.join(list(map(str, a[i]))))


from sys import stdin
stdin.readline

def mp():
	return list(map(int, stdin.readline().strip().split()))

def it():
	return int(stdin.readline().strip())
v = []
(m, n) = mp()
for _ in range(m):
	v += [mp()]
a = [[1 for _ in range(n)] for _ in range(m)]
c = [[0 for _ in range(n)] for _ in range(m)]
for i in range(m):
	for j in range(n):
		if v[i][j] == 0:
			for x in range(m):
				a[x][j] = 0
			for y in range(n):
				a[i][y] = 0
for i in range(m):
	for j in range(n):
		if a[i][j] == 1:
			for x in range(m):
				c[x][j] = 1
			for y in range(n):
				c[i][y] = 1
if c == v:
	print('YES')
	for i in range(m):
		print(*a[i])
else:
	print('NO')


(n, m) = tuple(map(int, input().split()))
grid = []
fulllines = set([])
for k in range(n):
	l = list(map(int, input().split()))
	if l == [1] * m:
		fulllines.add(k)
	grid.append(l)
fullcols = set([])
for i in range(m):
	b = True
	for j in range(n):
		if grid[j][i] == 0:
			b = False
	if b:
		fullcols.add(i)
res = []
for k in range(n):
	res.append([])
for i in range(n):
	for j in range(m):
		if i in fulllines and j in fullcols:
			res[i].append('1')
		else:
			res[i].append('0')
fres = []
cols = set()
for i in range(n):
	l = [0] * m
	for j in range(m):
		if res[i][j] == '1':
			l = [1] * m
			cols.add(j)
	fres.append(l)
for i in range(n):
	for j in range(m):
		if j in cols:
			fres[i][j] = 1
if fres == grid:
	print('YES')
	for k in range(n):
		print(' '.join(res[k]))
else:
	print('NO')


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
(m, n) = rinput()
A = []
for _ in range(m):
	A.append(rlinput())
visited = [[1 for i in range(n)] for j in range(m)]
for i in range(m):
	for j in range(n):
		if A[i][j] == 0:
			for k in range(n):
				visited[i][k] = 0
			for k in range(m):
				visited[k][j] = 0
B = [[-1 for i in range(n)] for j in range(m)]
for i in range(m):
	for j in range(n):
		B[i][j] = 0
		for k in range(n):
			if visited[i][k] == 1:
				B[i][j] = 1
				break
		else:
			for k in range(m):
				if visited[k][j] == 1:
					B[i][j] = 1
					break
if A == B:
	print('YES')
	for row in visited:
		print(*row)
else:
	print('NO')


from collections import defaultdict
g = defaultdict(list)
row = defaultdict(int)
column = defaultdict(int)
ng = defaultdict(list)
gg = defaultdict(list)
(n, m) = (int(x) for x in input('').split())
for i in range(n):
	g[i] = [int(x) for x in input('').split()]
	ng[i] = [0] * m
	gg[i] = [0] * m
for i in range(n):
	row[i] = all(g[i])
for j in range(m):
	column[j] = all((g[i][j] for i in range(n)))
for i in range(n):
	for j in range(m):
		ng[i][j] = int(row[i] and column[j])
for i in range(n):
	if any(ng[i]):
		gg[i] = [1] * m
for j in range(m):
	if any((ng[i][j] for i in range(n))):
		for i in range(n):
			gg[i][j] = 1
if gg == g:
	print('YES')
	for i in range(n):
		print(' '.join((str(x) for x in ng[i])))
else:
	print('NO')


(n, m) = map(int, input().split())
A = [[1 for j in range(m)] for i in range(n)]
B = []
for i in range(n):
	b = list(map(int, input().split()))
	B.append(b)
ind_i = []
ind_j = []
for i in range(n):
	for j in range(m):
		if B[i][j] == 0:
			ind_i.append(i)
			ind_j.append(j)
for i in ind_i:
	for j in range(m):
		A[i][j] = 0
for i in range(n):
	for j in ind_j:
		A[i][j] = 0
C = [[0 for j in range(m)] for i in range(n)]
for i in range(n):
	for j in range(m):
		for k in range(n):
			C[k][j] = C[k][j] or A[i][j]
		for k in range(m):
			C[i][k] = C[i][k] or A[i][j]
if C == B:
	print('YES')
	for i in range(n):
		print(*A[i])
else:
	print('NO')


class CodeforcesTask486BSolution:

	def __init__(self):
		self.result = ''
		self.m_n = []
		self.matrix = []

	def read_input(self):
		self.m_n = [int(x) for x in input().split(' ')]
		for x in range(self.m_n[0]):
			self.matrix.append([int(y) for y in input().split(' ')])

	def process_task(self):
		rows = [sum(row) == self.m_n[1] for row in self.matrix]
		cols = [False] * self.m_n[1]
		for x in range(self.m_n[1]):
			col = 0
			for y in range(self.m_n[0]):
				col += self.matrix[y][x]
			if col == self.m_n[0]:
				cols[x] = True
		can = True
		for x in range(self.m_n[0]):
			for y in range(self.m_n[1]):
				if self.matrix[x][y]:
					if not (rows[x] or cols[y]):
						can = False
						break
			if not can:
				break
		if sum([1 if x else 0 for x in cols]) and (not sum([1 if x else 0 for x in rows])) or (sum([1 if x else 0 for x in rows]) and (not sum([1 if x else 0 for x in cols]))):
			can = False
		if can:
			new_matrix = []
			for y in range(self.m_n[0]):
				row = []
				for x in range(self.m_n[1]):
					row.append(1 if rows[y] and cols[x] else 0)
				new_matrix.append(row)
			self.result = 'YES\n{0}'.format('\n'.join([' '.join([str(x) for x in row]) for row in new_matrix]))
		else:
			self.result = 'NO'

	def get_result(self):
		return self.result
Solution = CodeforcesTask486BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
p = [[1 for i in range(m)] for j in range(n)]
for i in range(n):
	for j in range(m):
		if l[i][j] == 0:
			p[i] = [0 for x in range(m)]
			for k in range(n):
				p[k][j] = 0
q = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	for j in range(m):
		if p[i][j] == 1:
			q[i] = [1 for y in range(m)]
			for k in range(n):
				q[k][j] = 1
if q == l:
	print('YES')
	for i in p:
		print(*i)
else:
	print('NO')


def main():
	from sys import stdin, stdout
	(n, m) = map(int, stdin.readline().split())
	b = []
	for _ in range(n):
		b.append(list(map(int, stdin.readline().split())))
	col = []
	row = []
	for i in range(n):
		col.append(all(b[i]))
	for j in range(m):
		x = 1
		for k in range(n):
			x &= b[k][j]
		row.append(x)
	a = []
	for i in range(n):
		sub = []
		for j in range(m):
			sub.append(col[i] & row[j])
		a.append(sub)
	row = []
	col = []
	for i in range(n):
		row.append(any(a[i]))
	for i in range(m):
		x = 0
		for j in range(n):
			x |= a[j][i]
		col.append(x)
	b_new = []
	for i in range(n):
		sub = []
		for j in range(m):
			sub.append(row[i] | col[j])
		b_new.append(sub)
	if b == b_new:
		stdout.write('YES\n')
		for i in range(n):
			for j in range(m):
				stdout.write(str(a[i][j]) + ' ')
			stdout.write('\n')
	else:
		stdout.write('NO')
main()


import math
from collections import Counter
L = lambda : list(map(int, input().split()))
M = lambda : map(int, input().split())
I = lambda : int(input())
IN = lambda : input()
mod = 10 ** 9 + 7

def s(a):
	print(' '.join(list(map(str, a))))
(m, n) = M()
a = []
for i in range(m):
	a.append(L())
b = []
for i in range(m):
	b.append([1] * n)
for i in range(m):
	for j in range(n):
		if a[i][j] == 0:
			for k in range(n):
				b[i][k] = 0
			for k in range(m):
				b[k][j] = 0
for i in range(m):
	for j in range(n):
		if a[i][j] == 1:
			f = 0
			for k in range(n):
				if b[i][k] == 1:
					f = 1
			for k in range(m):
				if b[k][j] == 1:
					f = 1
			if f == 0:
				print('NO')
				exit()
print('YES')
for i in range(m):
	print(*b[i])


def Solve(B, m, n):
	A = [[-1 for x in range(n)] for y in range(m)]
	zeroes = []
	ones = []
	for i in range(m):
		for j in range(n):
			if B[i][j] == 0:
				zeroes.append((i, j))
			else:
				ones.append((i, j))
	for zero in zeroes:
		x = zero[0]
		y = zero[1]
		for i in range(n):
			A[x][i] = 0
		for i in range(m):
			A[i][y] = 0
	for i in range(m):
		for j in range(n):
			if A[i][j] == -1:
				A[i][j] = 1
	for i in range(m):
		for j in range(n):
			ans = 0
			for x in range(n):
				ans = ans | A[i][x]
			for x in range(m):
				ans = ans | A[x][j]
			if ans != B[i][j]:
				print('NO')
				return
	print('YES')
	for i in range(m):
		for j in range(n):
			print(A[i][j], end=' ')
		print()

def main():
	(m, n) = map(int, input().split())
	B = []
	for i in range(m):
		row = list(map(int, input().split()))
		B.append(row)
	Solve(B, m, n)
main()


(m, n) = map(int, input().split())
A = [[1] * n] * m
B = [[0] * n] * m
C = []
for i in range(m):
	L = list(map(int, input().split()))
	C.append(L)
	for j in range(len(L)):
		if L[j] == 0:
			A[i] = [0] * n
			for k in range(m):
				A[k][j] = 0
for p in range(m):
	for w in range(n):
		if A[p][w] == 1:
			B[p] = [1] * n
			for s in range(m):
				B[s][w] = 1
if B == C:
	print('YES')
	for i in A:
		print(*i)
else:
	print('NO')


(m, n) = map(int, input().split())
B = []
A = [[1 for i in range(n)] for j in range(m)]
for i in range(m):
	B.append(list(map(int, input().split())))
for i in range(m):
	for j in range(n):
		if B[i][j] == 0:
			A[i] = [0] * n
			for k in range(m):
				A[k][j] = 0
for i in range(m):
	for j in range(n):
		temp1 = 1
		temp2 = 1
		if B[i][j] == 1:
			temp1 = 0
			temp2 = 0
			for k in range(n):
				if A[i][k] != 0:
					temp1 = 1
			for l in range(m):
				if A[l][j] != 0:
					temp2 = 1
			if temp1 == 0 and temp2 == 0:
				break
	if temp1 == 0 and temp2 == 0:
		break
if temp1 == 0 and temp2 == 0:
	print('NO')
else:
	print('YES')
	for i in range(m):
		print(' '.join((str(x) for x in A[i])))


(m, n) = list(map(int, input().split(' ')))
B = []
for i in range(0, m):
	row = [int(x) for x in input().split(' ')]
	B.append(row)
B_ = []
for j in range(0, n):
	col = [B[i][j] for i in range(0, m)]
	B_.append(col)
for row in B:
	if 1 in row:
		if 0 in row:
			for j in range(0, n):
				col = [B[i][j] for i in range(0, m)]
				if row[j] == 1 and 0 in col:
					print('NO')
					return
for col in B_:
	if 1 in col:
		if 0 in col:
			for i in range(0, m):
				row = [B[i][j] for j in range(0, n)]
				if col[i] == 1 and 0 in row:
					print('NO')
					return
only1 = False
only0 = False
for row in B:
	if 1 not in row:
		only0 = True
	if 0 not in row:
		only1 = True
if only1 and only0:
	print('NO')
	return
only1 = False
only0 = False
for col in B_:
	if 1 not in col:
		only0 = True
	if 0 not in col:
		only1 = True
if only1 and only0:
	print('NO')
	return
A = [[0 for col in range(0, n)] for row in range(0, m)]
R = []
for i in range(0, m):
	flg = 1
	for j in range(0, n):
		if B[i][j] == 0:
			flg = 0
			break
	if flg == 1:
		R.append(i)
C = []
for j in range(0, n):
	flg = 1
	for i in range(0, m):
		if B[i][j] == 0:
			flg = 0
			break
	if flg == 1:
		C.append(j)
for r in R:
	for c in C:
		A[r][c] = 1
print('YES')
for i in range(0, m):
	s = '' + str(A[i][0])
	for j in range(1, n):
		s += ' ' + str(A[i][j])
	print(s)


def main():
	(n, m) = map(int, input().split())
	l = tuple((tuple(map(int, input().split())) for _ in range(n)))
	res = [[1] * m for _ in range(n)]
	for (y, row) in enumerate(l):
		for (x, f) in enumerate(row):
			if not f:
				res[y] = [0] * m
				for rr in res:
					rr[x] = 0
	for (y, row) in enumerate(l):
		for (x, f) in enumerate(row):
			if f:
				if not (any(res[y]) or any((rr[x] for rr in res))):
					print('NO')
					return
	print('YES')
	for rr in res:
		print(*rr)
main()


from sys import stdin

def main():
	(m, n) = map(int, stdin.readline().split())
	b = []
	for _ in range(m):
		b.append(list(map(int, stdin.readline().split())))
	a = [[0 for _ in range(n)] for _ in range(m)]
	for i in range(m):
		for j in range(n):
			if all((b[i][k] == 1 for k in range(n))) and all((b[k][j] == 1 for k in range(m))):
				a[i][j] = 1
	ok = True
	for i in range(m):
		for j in range(n):
			curr = 0
			for k in range(n):
				curr = curr or a[i][k]
			for k in range(m):
				curr = curr or a[k][j]
			if curr != b[i][j]:
				ok = False
				break
	if not ok:
		print('NO')
	else:
		print('YES')
		for r in a:
			print(*r)
main()


def ok(AA, resB):
	realB = []
	for i in range(0, m):
		realBrow = []
		for j in range(0, n):
			res = 0
			for k in range(0, m):
				res += AA[k][j]
			for k in range(0, n):
				res += AA[i][k]
			if res > 0:
				res = 1
			realBrow.append(res)
		realB.append(realBrow)
	for i in range(0, m):
		for j in range(0, n):
			if realB[i][j] != resB[i][j]:
				return False
	return True
[m, n] = input().split(' ')
m = int(m)
n = int(n)
B = []
A = []
for i in range(0, m):
	brow = input().split(' ')
	arow = []
	for j in range(0, n):
		brow[j] = int(brow[j])
		arow.append(1)
	B.append(brow)
	A.append(arow)
for i in range(0, m):
	for j in range(0, n):
		if B[i][j] == 0:
			for k in range(0, m):
				A[k][j] = 0
			for k in range(0, n):
				A[i][k] = 0
if ok(A, B):
	print('YES')
	for i in range(0, m):
		for j in range(0, n):
			A[i][j] = str(A[i][j])
		print(' '.join(A[i]))
else:
	print('NO')


(n, m) = list(map(int, input().split()))
a = [[0] * m for i in range(n)]
for i in range(n):
	b = list(map(int, input().rstrip().split()))
	for j in range(m):
		a[i][j] = b[j]
dp = [[-1] * m for i in range(n)]
flag = 0
for i in range(n):
	for j in range(m):
		if a[i][j] == 0:
			for k in range(m):
				dp[i][k] = 0
			for k in range(n):
				dp[k][j] = 0
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			fla1 = 0
			for k in range(m):
				if dp[i][k] == 1:
					fla1 = 1
					break
			for k in range(n):
				if dp[k][j] == 1:
					fla1 = 1
					break
			if fla1 == 1:
				continue
			else:
				for k in range(m):
					if dp[i][k] == -1:
						dp[i][k] = 1
						fla1 = 1
						break
				for k in range(n):
					if dp[k][j] == -1:
						dp[k][j] = 1
						fla1 = 1
						break
				if fla1 == 1:
					continue
				else:
					flag = 1
					break
	if flag == 1:
		break
if flag == 1:
	print('NO')
else:
	print('YES')
	for i in range(n):
		for j in range(m):
			if dp[i][j] == -1:
				dp[i][j] = 0
	for i in dp:
		print(*i)


(a, b) = map(int, input().split())
ans = [[0] * b for i in ' ' * a]
z = [list(map(int, input().split())) for _ in ' ' * a]
_z = [[z[j][i] for j in range(a)] for i in range(b)]
ok = 0
for i in range(a):
	for j in range(b):
		if z[i][j] == 1:
			ok += 1
			if sum(z[i]) == b and sum(_z[j]) == a:
				ans[i][j] = 1
			elif sum(z[i]) != b and sum(_z[j]) != a:
				exit(print('NO'))
k = sum((sum(ans[i]) for i in range(a)))
if k == 0 and ok:
	exit(print('NO'))
print('YES')
for i in ans:
	print(*i)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(m, n) = f()
l = []
la = [[0 for i in range(n)] for j in range(m)]
for _ in range(m):
	l.append(il())
for i in range(m):
	for j in range(n):
		if all((l[k][j] for k in range(m))) and all((l[i][k] for k in range(n))):
			la[i][j] = 1
for i in range(m):
	for j in range(n):
		o = la[i][j]
		for k in range(n):
			o = o or la[i][k]
		for k in range(m):
			o = o or la[k][j]
		if o != l[i][j]:
			exit(print('NO'))
print('YES')
for i in range(m):
	print(*la[i])


import sys
import bisect
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque
from collections import Counter as c
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(var)

def l():
	return list(map(int, data().split()))

def sl():
	return list(map(str, data().split()))

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
(m, n) = sp()
b = list()
for i in range(m):
	b.append(l())
a = l2d(n, m, 1)
(r, c) = (set(), set())
for i in range(m):
	for j in range(n):
		if b[i][j] == 0:
			r.add(i)
			c.add(j)
for i in r:
	for j in range(n):
		a[i][j] = 0
for i in c:
	for j in range(m):
		a[j][i] = 0
rowor = list()
for i in range(m):
	temp = 0
	for j in range(n):
		temp = temp | a[i][j]
		if temp == 1:
			break
	rowor.append(temp)
color = list()
for i in range(n):
	temp = 0
	for j in range(m):
		temp = temp | a[j][i]
		if temp == 1:
			break
	color.append(temp)
result = True
for i in range(m):
	for j in range(n):
		temp = rowor[i] | color[j]
		if temp != b[i][j]:
			result = False
	if not result:
		break
if result:
	print('YES')
	for i in a:
		print(*i)
	exit()
print('NO')


(m, n) = map(int, input().split())
b = [] * m
for _ in range(m):
	b.append([int(x) for x in input().split()])
rows = [1] * m
cols = [1] * n
for i in range(0, m):
	for j in range(0, n):
		if b[i][j] == 0:
			rows[i] = 0
			cols[j] = 0
a = [[1 for i in range(n)] for j in range(m)]
for i in range(0, m):
	for j in range(0, n):
		if rows[i] == 0 or cols[j] == 0:
			a[i][j] = 0
rows = [0] * m
cols = [0] * n
for i in range(0, m):
	for j in range(0, n):
		if a[i][j] == 1:
			rows[i] = 1
			cols[j] = 1
bnew = [[0 for i in range(n)] for j in range(m)]
for i in range(0, m):
	for j in range(0, n):
		if rows[i] == 1 or cols[j] == 1:
			bnew[i][j] = 1
if bnew == b:
	print('YES')
	for i in range(m):
		for x in a[i]:
			print(x, end=' ')
		print()
else:
	print('NO')


def main():
	(n, m) = map(int, input().split())
	a = [[1 for i in range(m)] for __ in range(n)]
	ones = []
	zer_r = [1 for i in range(n)]
	zer_c = [1 for j in range(m)]
	for i in range(n):
		b = list(map(int, input().split()))
		for j in range(m):
			if b[j] == 0:
				zer_r[i] = 0
				zer_c[j] = 0
			else:
				ones.append((i, j))
	poss = True
	for i in ones:
		if zer_r[i[0]] == 0 and zer_c[i[1]] == 0:
			poss = False
	if sum(zer_r) == 0 and sum(zer_c) >= 1 or (sum(zer_c) == 0 and sum(zer_r) >= 1):
		poss = False
	if poss:
		for i in range(n):
			for j in range(m):
				if zer_r[i] and zer_c[j]:
					a[i][j] = 1
				else:
					a[i][j] = 0
		print('YES')
		for i in a:
			print(*i)
	else:
		print('NO')
main()


(m, n) = map(int, input().split())
mat = []
for i in range(m):
	mat.append(list(map(int, input().split())))
ans = [[1] * n for i in range(m)]
for i in range(m):
	for j in range(n):
		if mat[i][j] == 0:
			for k in range(m):
				ans[k][j] = 0
			for k in range(n):
				ans[i][k] = 0
f = True
for i in range(m):
	for j in range(n):
		if mat[i][j] == 1:
			if 1 not in [ans[k][j] for k in range(m)] and 1 not in [ans[i][k] for k in range(n)]:
				f = False
if f == False:
	print('NO')
else:
	print('YES')
	for i in ans:
		print(' '.join(map(str, i)))


(n, m) = map(int, input().split())
a = []
count1 = 0
for _ in range(n):
	l = [int(x) for x in input().split()]
	count1 += l.count(1)
	a += [l]
ans = []
for _ in range(n):
	l = [1 for x in range(m)]
	ans += [l]
flag = 0
for i in range(n):
	for j in range(m):
		c = 0
		if a[i][j] == 0:
			for k in range(n):
				ans[k][j] = 0
			for k in range(m):
				ans[i][k] = 0
		else:
			for k in range(n):
				if a[k][j] == 0:
					c += 1
					break
			for k in range(m):
				if a[i][k] == 0:
					c += 1
					break
			if c == 2:
				flag = 1
				break
	if flag == 1:
		break
c = 0
for i in range(n):
	c += ans[i].count(1)
if c == 0 and count1 != 0 or flag == 1:
	print('NO')
else:
	print('YES')
	for i in range(n):
		print(*ans[i])


(n, m) = map(int, input().split())
l_n = list()
for _ in range(n):
	l_n.append(list(map(int, input().split())))
res = [[1 for _ in range(m)] for _ in range(n)]
for i in range(len(l_n)):
	for j in range(len(l_n[i])):
		if l_n[i][j] == 0:
			for k in range(n):
				res[k][j] = 0
			for l in range(m):
				res[i][l] = 0
for i in range(n):
	for j in range(m):
		if l_n[i][j]:
			if not (any(res[i]) or any((rr[j] for rr in res))):
				print('NO')
				quit()
print('YES')
for row in res:
	print(' '.join((str(x) for x in row)))


__author__ = 'runekri3'

def get_answer():
	(m, n) = list(map(int, input().split()))
	(total_rows, total_cols) = (m, n)
	rows = []
	for row_i in range(total_rows):
		row = list(map(int, input().split()))
		rows.append(row)
	cols = [[row[col_i] for row in rows] for col_i in range(total_cols)]
	filled_rows = []
	must_be_filled_cols = set()
	for (row_i, row) in enumerate(rows):
		ones = row.count(1)
		if ones != 0:
			if ones != total_cols:
				[must_be_filled_cols.add(col_i) for col_i in range(total_cols) if row[col_i] == 1]
			else:
				filled_rows.append(row_i)
	if len(filled_rows) == total_rows:
		must_be_filled_cols = set(range(total_cols))
	if len(must_be_filled_cols) == 0 or len(filled_rows) == 0:
		if len(must_be_filled_cols) != 0 or len(filled_rows) != 0:
			print('NO')
			return
	for must_be_filled_col_i in must_be_filled_cols:
		col = cols[must_be_filled_col_i]
		ones = col.count(1)
		if ones != total_rows:
			print('NO')
			return
	solution_matrix = [[0 for _ in range(total_cols)] for _ in range(total_rows)]
	for row_i in filled_rows:
		if len(must_be_filled_cols) == 0:
			solution_matrix[row_i] = [1] * total_cols
		for col_i in must_be_filled_cols:
			solution_matrix[row_i][col_i] = 1
	print('YES')
	[print(' '.join(map(str, row))) for row in solution_matrix]
get_answer()


from functools import reduce

def foldM0(mat, n, m, f):
	ret = [x[:] for x in mat]
	for i in range(n):
		v = reduce(f, [mat[i][j] for j in range(m)])
		for j in range(m):
			ret[i][j] = v
	for i in range(m):
		v = reduce(f, [mat[j][i] for j in range(n)])
		for j in range(n):
			ret[j][i] = f(ret[j][i], v)
	return ret

def solve(mat, n, m):
	matpo = foldM0(mat, n, m, lambda x, y: x & y)
	if mat == foldM0(matpo, n, m, lambda x, y: x | y):
		print('YES')
		print('\n'.join((' '.join((str(x) for x in xs)) for xs in matpo)))
	else:
		print('NO')
(n, m) = map(int, input().split())
mat = []
for i in range(n):
	mat.append(list(map(int, input().split())))
solve(mat, n, m)


import sys

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans
mod = int(1000000000.0) + 7

def sinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def ninp():
	return map(int, sys.stdin.readline().strip().split())

def llinp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math as m
(m, n) = ninp()
ans = [[1 for i in range(n)] for j in range(m)]
mat = []
for i in range(0, m):
	a = llinp()
	mat.append(a)
for i in range(0, m):
	for j in range(0, n):
		if mat[i][j] == 0:
			for x in range(0, n):
				ans[i][x] = 0
			for x in range(0, m):
				ans[x][j] = 0
for i in range(0, m):
	for j in range(0, n):
		f1 = 0
		f2 = 0
		if mat[i][j] == 1:
			if 1 in ans[i]:
				f1 = 1
			for x in range(m):
				if ans[x][j] == 1:
					f2 = 1
			if f1 == 1 or f2 == 1:
				pass
			else:
				print('NO')
				exit()
print('YES')
for i in ans:
	print(*i)


import sys
(m, n) = map(int, input().split())
a = []
for _ in range(m):
	a.append(list(map(int, input().split())))
b = [[1] * n for _ in range(m)]
for i in range(m):
	for j in range(n):
		if a[i][j] == 0:
			b[i] = [0] * n
			for k in range(m):
				b[k][j] = 0
for i in range(m):
	for j in range(n):
		if a[i][j] == 1:
			good = False
			if 1 in b[i]:
				good = True
			else:
				for k in range(m):
					if b[k][j] == 1:
						good = True
			if not good:
				print('NO')
				return
print('YES')
for i in b:
	print(' '.join([str(t) for t in i]))


(m, n) = map(int, input().split())
arr = []
for _ in range(m):
	x = list(map(int, input().split()))
	arr.append(x)
A = [[-1 for i in range(n)] for j in range(m)]
for i in range(m):
	for j in range(n):
		if arr[i][j] == 0:
			for k in range(m):
				A[k][j] = 0
			for k in range(n):
				A[i][k] = 0
for i in range(m):
	for j in range(n):
		if A[i][j] == -1:
			A[i][j] = 1
B1 = [[-1 for i in range(n)] for j in range(m)]
for i in range(m):
	for j in range(n):
		bool_1 = A[0][j]
		bool_2 = A[i][0]
		for k in range(m):
			bool_1 = bool_1 or A[k][j]
		for k in range(n):
			bool_2 = bool_2 or A[i][k]
		B1[i][j] = bool_1 or bool_2
if B1 == arr:
	print('YES')
	for i in range(m):
		for j in range(n):
			if j != n - 1:
				print(A[i][j], end=' ')
			else:
				print(A[i][j])
else:
	print('NO')


from array import *
(m, n) = list(map(int, input().split()))
A = []
for i in range(m):
	k = list(map(int, input().split()))
	A.append(k)
ans = [[-1 for x in range(n)] for y in range(m)]
flag = 0
for i in range(m):
	if flag:
		break
	for j in range(n):
		if A[i][j] == 0:
			for a in range(n):
				if ans[i][a] == -1 or ans[i][a] == 0:
					ans[i][a] = 0
				else:
					print('NO')
					flag = 1
					break
			if flag:
				break
			for b in range(m):
				if ans[b][j] == -1 or ans[b][j] == 0:
					ans[b][j] = 0
				else:
					print('NO')
					flag = 1
					break
for i in range(m):
	if flag:
		break
	for j in range(n):
		if ans[i][j] == -1:
			if A[i][j] == 1:
				ans[i][j] = 1
			else:
				print('NO')
				flag = 1
				break
for i in range(m):
	check = 0
	if flag:
		break
	for j in range(n):
		check = 0
		if A[i][j] == 1:
			for a in range(n):
				if ans[i][a] == 1:
					check = 1
			for b in range(m):
				if ans[b][j] == 1:
					check = 1
			if check:
				continue
			else:
				flag = 1
				print('NO')
				break
if flag == 0:
	print('YES')
	for i in ans:
		for j in i:
			print(j, end=' ')
		print()


(r, c) = map(int, input().strip().split())
l = []
result = []
for i in range(r):
	a = list(map(int, input().strip().split()))
	l.append(a)
	result.append([1] * c)
for i in range(r):
	for j in range(c):
		if l[i][j] == 0:
			result[i] = [0] * c
			for k in range(r):
				result[k][j] = 0
flag = 0
for i in range(r):
	for j in range(c):
		check = 0
		if 1 in result[i]:
			check = 1
		for k in range(r):
			if result[k][j] == 1:
				check = 1
				break
		if check != l[i][j]:
			print('NO')
			flag = 1
			break
	if flag == 1:
		break
if flag == 0:
	print('YES')
	for i in result:
		print(*i)


import sys

def input():
	return sys.stdin.readline().strip()
(m, n) = map(int, input().split())
b = [0 for i in range(m)]
for i in range(m):
	b[i] = [int(i) for i in input().split()]
row = [0 for i in range(m)]
col = [0 for i in range(n)]
for i in range(m):
	for j in range(n):
		if not b[i][j]:
			row[i] = 1
			col[j] = 1
a = [[1 for i in range(n)] for j in range(m)]
zero = [0 for i in range(n)]
row_val = [0 for i in range(m)]
col_val = [0 for i in range(n)]
for i in range(m):
	if row[i]:
		a[i] = zero
for i in range(n):
	if col[i]:
		for j in range(m):
			a[j][i] = 0
for i in range(m):
	for j in range(n):
		if a[i][j]:
			col_val[j] = 1
			row_val[i] = 1
possible = True
for i in range(m):
	for j in range(n):
		if b[i][j] != (row_val[i] or col_val[j]):
			possible = False
			break
if possible:
	print('YES')
	for i in range(m):
		for j in range(n):
			print(a[i][j], end=' ')
		print()
else:
	print('NO')


from sys import stdin
input = stdin.readline
from heapq import heapify, heappush, heappop, heappushpop
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt, log
from bisect import bisect_left as bl, bisect_right as br
from itertools import combinations as c, permutations as p
from math import factorial as f, ceil, gcd, sqrt, log
mi = lambda : map(int, input().split())
ii = lambda : int(input())
li = lambda : list(map(int, input().split()))
mati = lambda r: [li() for _ in range(r)]
lcm = lambda a, b: a * b // gcd(a, b)

def solve():
	(n, m) = mi()
	arr = []
	for x in range(n):
		arr.append(li())
	p = [[1 for x in range(m)] for x in range(n)]
	for x in range(n):
		for y in range(m):
			if arr[x][y] == 0:
				p[x] = [0 for l in range(m)]
				for z in range(n):
					p[z][y] = 0
	k = [[0 for x in range(m)] for y in range(n)]
	for x in range(n):
		for y in range(m):
			if p[x][y] == 1:
				k[x] = [1 for o in range(m)]
				for z in range(n):
					k[z][y] = 1
	if k == arr:
		print('YES')
		for x in p:
			print(*x)
	else:
		print('NO')
for _ in range(1):
	solve()


from sys import stdin, stdout
from math import gcd
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
(m, n) = iia()
arr = []
for _ in range(m):
	arr.append(iia())
narr = [[1 for i in range(n)] for j in range(m)]
for i in range(m):
	for j in range(n):
		if arr[i][j] == 0:
			for k in range(m):
				narr[k][j] = 0
			for k in range(n):
				narr[i][k] = 0
ans = []
for i in range(m):
	temp = []
	for j in range(n):
		cur = narr[i][j]
		for k in range(m):
			cur = cur | narr[k][j]
		for k in range(n):
			cur = cur | narr[i][k]
		temp.append(cur)
	ans.append(temp)
if ans == arr:
	print('YES')
	for i in narr:
		print(*i)
else:
	print('NO')


(m, n) = map(int, input().split())
a = []
for i in range(m):
	a.append(list(map(int, input().split())))
ans = [[1] * n for i in range(m)]
for i in range(m):
	for j in range(n):
		if a[i][j] == 0:
			for k in range(n):
				ans[i][k] = 0
			for k in range(m):
				ans[k][j] = 0
flag = 0
for i in range(m):
	for j in range(n):
		if a[i][j] == 1:
			flag = 0
			for k in range(n):
				if ans[i][k] == 1:
					flag = 1
			for k in range(m):
				if ans[k][j] == 1:
					flag = 1
			if flag == 0:
				print('NO')
				exit()
print('YES')
for i in range(m):
	print(*ans[i])


(n, m) = map(int, input().split())
M = [list(map(int, input().split())) for i in range(n)]
M1 = [[-1 for i in range(m)] for i in range(n)]
for i in range(n):
	for j in range(m):
		if M[i][j] == 0:
			for i1 in range(m):
				M1[i][i1] = 0
			for i1 in range(n):
				M1[i1][j] = 0
for i in range(n):
	for j in range(m):
		if M1[i][j] == -1:
			M1[i][j] = 1
T = 'YES'
for i in range(n):
	for j in range(m):
		c = 0
		if M[i][j] == 0:
			for i1 in range(m):
				if M1[i][i1] != 0:
					c = 1
					break
			for i1 in range(n):
				if M1[i1][j] != 0:
					c = 1
					break
		else:
			c = 1
			for i1 in range(m):
				if M1[i][i1] != 0:
					c = 0
					break
			for i1 in range(n):
				if M1[i1][j] != 0:
					c = 0
					break
		if c == 1:
			T = 'NO'
			break
print(T)
if T == 'YES':
	for i in range(n):
		print(*M1[i])


(m, n) = [int(s) for s in input().split(' ')]
B = [[] for _ in range(m)]
A = [[1 for _ in range(n)] for _ in range(m)]
ARow = [n for _ in range(m)]
ACol = [m for _ in range(n)]
for i in range(m):
	B[i] = [int(s) for s in input().split(' ')]
	for j in range(n):
		if B[i][j] == 0:
			for x in range(m):
				A[x][j] = 0
				if ACol[j] > 0:
					ARow[x] = max(ARow[x] - 1, 0)
			for y in range(n):
				A[i][y] = 0
				if ARow[i] > 0:
					ACol[y] = max(ACol[y] - 1, 0)
			ARow[i] = 0
			ACol[j] = 0
contradiction = False
for i in range(m):
	if contradiction:
		break
	for j in range(n):
		if B[i][j] == 1:
			contradiction = ARow[i] == 0 and ACol[j] == 0
		if contradiction:
			break
if contradiction:
	print('NO')
else:
	print('YES')
	for i in range(m):
		print(' '.join(map(str, A[i])))


(a, b) = map(int, input().split())
ans = [[1] * b for i in ' ' * a]
z = [list(map(int, input().split())) for _ in ' ' * a]
for i in range(a):
	for j in range(b):
		if z[i][j] == 0:
			for k in range(b):
				ans[i][k] = 0
			for k in range(a):
				ans[k][j] = 0
o = []
for i in ans:
	s = i.copy()
	o.append(s)
for i in range(a):
	for j in range(b):
		if ans[i][j] == 1:
			for k in range(b):
				o[i][k] = 1
			for k in range(a):
				o[k][j] = 1
if o != z:
	print('NO')
else:
	print('YES')
	for i in ans:
		print(*i)


while True:
	try:

		def isvalid(r, c, mt, tmt):
			a = b = d = e = 0
			valid = True
			while a < r:
				while b < c:
					if mt[a][b] == 1:
						flag = False
						while d < r:
							if tmt[d][b] == 1:
								flag = True
							d += 1
						d = 0
						while e < c:
							if tmt[a][e] == 1:
								flag = True
							e += 1
						e = 0
						if not flag:
							valid = False
					b += 1
				a += 1
				b = 0
				if not valid:
					break
			if not valid:
				print('NO')
			else:
				print('YES')
				for i in range(r):
					print(*tmt[i])

		def solution(r, c, mt):
			tmt = [[1 for i in range(c)] for j in range(r)]
			a = 0
			b = 0
			cc = 0
			d = 0
			while a < r:
				while b < c:
					if mt[a][b] == 0:
						while cc < c:
							tmt[a][cc] = 0
							cc += 1
						cc = 0
						while d < r:
							tmt[d][b] = 0
							d += 1
						d = 0
					b += 1
				a += 1
				b = 0
			isvalid(r, c, mt, tmt)

		def read():
			(m, n) = map(int, input().split())
			mtrx = [list(map(int, input().split())) for i in range(m)]
			solution(m, n, mtrx)
		if __name__ == '__main__':
			read()
	except EOFError:
		break


vals = [int(x) for x in input().split()]
rows = vals[0]
cols = vals[1]
matrix = [[int(x) for x in input().split()] for _ in range(rows)]
rowsIsFullOfOne = [True] * rows
colIsFullOfOne = [True] * cols
for i in range(rows):
	for j in range(cols):
		if matrix[i][j] == 0:
			rowsIsFullOfOne[i] = False
			break
for i in range(cols):
	for j in range(rows):
		if matrix[j][i] == 0:
			colIsFullOfOne[i] = False
			break
result = [[0] * cols for _ in range(rows)]
for i in range(rows):
	for j in range(cols):
		if matrix[i][j] == 1 and colIsFullOfOne[j] and rowsIsFullOfOne[i]:
			result[i][j] = 1
matrixIsCorrect = True
for i in range(rows):
	for j in range(cols):
		matrixValue = 0
		for k in range(rows):
			matrixValue = matrixValue or result[k][j]
		for l in range(cols):
			matrixValue = matrixValue or result[i][l]
		if matrixValue != matrix[i][j]:
			matrixIsCorrect = False
if matrixIsCorrect:
	print('YES')
	for i in range(rows):
		rowRaw = ''
		for j in range(cols):
			rowRaw += str(result[i][j]) + ' '
		print(rowRaw)
else:
	print('NO')


(m, n) = map(int, input().split())
B = []
for i in range(m):
	B.append(list(map(int, input().split())))
A = [[1] * n for _ in range(m)]
for i in range(m):
	for j in range(n):
		if B[i][j] == 0:
			for k in range(m):
				A[k][j] = 0
			for t in range(n):
				A[i][t] = 0
OR_clms = [0] * n
OR_rows = [0] * m
for i in range(m):
	for j in range(n):
		OR_rows[i] = OR_rows[i] or A[i][j]
		OR_clms[j] = OR_clms[j] or A[i][j]
clone = []
for i in range(m):
	line = []
	for j in range(n):
		line.append(OR_rows[i] or OR_clms[j])
	clone.append(line)
for i in range(m):
	for j in range(n):
		if clone[i][j] != B[i][j]:
			print('NO')
			exit()
print('YES')
for i in range(m):
	print(*A[i])


from collections import Counter, defaultdict, deque
from math import factorial as fact

def primes(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return factors

def issubseq(s, t):
	if len(t) > len(s):
		return False
	lt = len(t)
	p = 0
	for el in s:
		if el == t[p]:
			p += 1
		if p == lt:
			return True
	return False
(m, n) = [int(x) for x in input().split()]
matrix = [[int(x) for x in input().split()] for k in range(m)]
rows = []
cols = []
res = [[0] * n for x in range(m)]
for i in range(m):
	if all(matrix[i]):
		rows.append(1)
	else:
		rows.append(0)
for i in range(n):
	ok = True
	for j in range(m):
		if matrix[j][i] == 0:
			ok = False
			break
	if ok:
		cols.append(1)
	else:
		cols.append(0)
for i in range(m):
	for j in range(n):
		res[i][j] = cols[j] and rows[i]
for i in range(m):
	for j in range(n):
		if matrix[i][j]:
			if any(res[i]) or any((res[x][j] for x in range(m))):
				pass
			else:
				print('NO')
				exit()
print('YES')
for el in res:
	print(*el)


(a, b) = map(int, input().split())
d = [list(map(int, input().split())) for i in range(a)]
ans = [list([0] * b) for i in range(a)]
n = 0
m = 0
for i in range(a):
	for j in range(b):
		if d[i][j] == 1:
			m = 1
			c = 1
			for k in range(b):
				if d[i][k] == 0:
					c = -1
			for k in range(a):
				if d[k][j] == 0:
					c = -1
			if c == 1:
				ans[i][j] = 1
				n = 1
if not m:
	print('YES')
	for i in range(a):
		print(*d[i])
elif not n:
	print('NO')
else:
	p = 0
	w = [list(ans[i]) for i in range(a)]
	for i in range(a):
		for j in range(b):
			if w[i][j] == 1:
				for k in range(b):
					ans[i][k] = 1
				for k in range(a):
					ans[k][j] = 1
	for i in range(a):
		for j in range(b):
			if d[i][j] != ans[i][j]:
				p = 1
				break
		if p:
			break
	if p:
		print('NO')
	else:
		print('YES')
		for i in range(a):
			print(*w[i])


(n, m) = list(map(int, input().split()))
mat = []
final = []
for i in range(n):
	mat.append(list(map(int, input().split())))
	final.append([1] * m)
ones = []
for i in range(n):
	for j in range(m):
		if mat[i][j] == 0:
			for k in range(n):
				final[k][j] = 0
			for k in range(m):
				final[i][k] = 0
		else:
			ones.append([i, j])
for point in ones:
	flag = False
	for k in range(n):
		if final[k][point[1]]:
			flag = True
	for k in range(m):
		if final[point[0]][k]:
			flag = True
	if flag:
		continue
	else:
		print('NO')
		break
else:
	print('YES')
	for i in final:
		print(*i)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
A = [[1 for i in range(m)] for j in range(n)]
B = [[int(i) for i in input().split()] for j in range(n)]
for i in range(n):
	for j in range(m):
		if B[i][j] == 0:
			A[i] = [0 for k in range(m)]
			for k in range(n):
				A[k][j] = 0
c = 0
for i in range(n):
	for j in range(m):
		s = 0
		for t in A[i]:
			s = s | t
		for p in range(n):
			s = s | A[p][j]
		if s != B[i][j]:
			print('NO')
			c = 1
			break
	if c == 1:
		break
if c == 0:
	print('YES')
	for i in A:
		for j in i[:-1]:
			print(j, end=' ')
		print(i[-1])


(n, m) = map(int, input().split())
l = []
ans = []
for i in range(n):
	k = list(map(int, input().split()))
	l.append(k)
temp = 0
count = 0
for i in range(n):
	for j in range(m):
		if l[i][j] == 1:
			flag = 0
			count += 1
			for k in range(n):
				if l[k][j] != 1:
					flag = 1
					break
			if flag != 0 and l[i] != [1] * m:
				temp = 1
				break
			if flag == 0 and l[i] == [1] * m:
				ans.append([i, j])
	if temp == 1:
		break
if len(ans) == 0 and count != 0:
	temp = 1
if temp == 0:
	print('YES')
	for i in range(n):
		for j in range(m):
			if [i, j] in ans:
				print(1, end=' ')
			else:
				print(0, end=' ')
		print()
else:
	print('NO')


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n, m) = I()
b = []
for i in range(n):
	b.append(I())
ans = [[1] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		if b[i][j] == 0:
			for x in range(n):
				ans[x][j] = 0
			for x in range(m):
				ans[i][x] = 0
mb = [[0] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		if ans[i][j] == 1:
			for x in range(n):
				mb[x][j] = 1
			for x in range(m):
				mb[i][x] = 1
if mb == b:
	print('YES')
	for i in ans:
		print(*i)
else:
	print('NO')


(a, b) = map(int, input().split())
array = [list(map(int, input().split())) for _ in range(a)]
tmp = [[1 for _ in range(b)] for _ in range(a)]

def f(array):
	return 1 in array
for i in range(a):
	for j in range(b):
		if array[i][j] == 0:
			for p in range(a):
				tmp[p][j] = 0
			for p in range(b):
				tmp[i][p] = 0
for i in range(a):
	for j in range(b):
		if array[i][j] != f([tmp[i][t] for t in range(b)] + [tmp[t][j] for t in range(a)]):
			print('NO')
			exit()
print('YES')
print('\n'.join(map(lambda t: ' '.join(map(str, t)), tmp)))


from math import *
(n, m) = input().split()
(n, m) = (int(n), int(m))
b = [[int(i) for i in input().split()] for i in range(n)]
a = [[1] * m for i in range(n)]
c = [[0] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		if b[i][j] == 0:
			for k in range(m):
				a[i][k] = 0
			for k in range(n):
				a[k][j] = 0
for i in range(n):
	for j in range(m):
		c[i][j] = 0
		for k in range(m):
			if a[i][k] == 1:
				c[i][j] = 1
				break
		if c[i][j] == 1:
			continue
		for k in range(n):
			if a[k][j] == 1:
				c[i][j] = 1
				break
bad = False
for i in range(n):
	for j in range(m):
		if c[i][j] != b[i][j]:
			bad = True
			print('NO')
			break
	if bad:
		break
if not bad:
	print('YES')
	for i in range(n):
		for j in range(m):
			print(a[i][j], end=' ')
		print()


(m, n) = map(int, input().split())
l = []
for i in range(m):
	l.append(list(map(int, input().split())))
r = []
c = []
f = 0
for i in range(m):
	for j in range(n):
		if l[i][j] == 1:
			x = 1
			for k in range(m):
				if l[k][j] == 0:
					x = 0
					break
			if x == 1:
				c.append(j)
				for k in range(n):
					if l[i][k] == 0:
						x = 0
						break
				if x == 1:
					r.append(i)
			else:
				for k in range(n):
					if l[i][k] == 0:
						x = 1
						break
				if x == 0:
					r.append(i)
				else:
					f = 1
					break
if f == 1 or (len(r) == 0 and len(c) != 0) or (len(c) == 0 and len(r) != 0):
	print('NO')
else:
	print('YES')
	for i in range(m):
		for j in range(n):
			if i in r and j in c:
				print(1, end=' ')
			else:
				print(0, end=' ')
		print()


(n, m) = map(int, input().split())
arr = []
for i in range(n):
	arr.append(list(map(int, input().split())))
new = [[1 for i in range(m)] for i in range(n)]
dic = {}
for i in range(n):
	for j in range(m):
		if arr[i][j] == 0:
			for k in range(n):
				new[k][j] = 0
			for k in range(m):
				new[i][k] = 0
ones = {}
final = [[0 for i in range(m)] for i in range(n)]
for i in range(n):
	for j in range(m):
		if new[i][j] == 1:
			for k in range(n):
				final[k][j] = 1
			for k in range(m):
				final[i][k] = 1
if final == arr:
	print('YES')
	for i in range(n):
		print(*new[i])
else:
	print('NO')


(m, n) = list(map(int, input().split(' ')))
li = []
for x in range(m):
	li.append(list(map(int, input().split(' '))))
row = [0] * m
col = [0] * n
ranone = False
for x in range(m):
	for y in range(n):
		if li[x][y] == 1:
			ranone = True
			row[x] += 1
for x in range(n):
	for y in range(m):
		if li[y][x] == 1:
			ranone = True
			col[x] += 1
res = True
for x in range(m):
	for y in range(n):
		if li[x][y] == 1:
			if row[x] == n and col[y] == m:
				pass
			elif row[x] == n or col[y] == m:
				li[x][y] = 0
			else:
				res = False
if ranone == True:
	onefound = False
	for x in li:
		for y in x:
			if y == 1:
				onefound = True
				break
else:
	onefound = True
if res == False or onefound == False:
	print('NO')
else:
	print('YES')
	for x in li:
		for y in x:
			print(y, end=' ')
		print()


from sys import *
from math import *
from sys import stdin, stdout
from collections import *
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)

def ans():
	arr = []
	(m, n) = get_int()
	res = [[1 for i in range(n)] for j in range(m)]
	for i in range(m):
		mat = int_arr()
		arr.append(mat)
	for i in range(m):
		for j in range(n):
			if arr[i][j] == 0:
				for k in range(m):
					res[k][j] = 0
				for l in range(n):
					res[i][l] = 0
	for i in range(m):
		for j in range(n):
			if arr[i][j] == 1:
				su = 0
				for k in range(m):
					su += res[k][j]
				for l in range(n):
					su += res[i][l]
				if su == 0:
					print('NO')
					return
	print('YES')
	for i in range(m):
		print(*res[i])
ans()


import math, sys
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
from bisect import bisect_left, bisect_right
INF = float('inf')
MOD = int(1000000000.0) + 7
MAX = int(2000000.0)

def check(mat, n, m):
	ans = [[0 for i in range(m)] for j in range(n)]
	rows = [0 for i in range(n)]
	cols = [0 for i in range(m)]
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 1:
				rows[i] = 1
				cols[j] = 1
	for i in range(n):
		for j in range(m):
			ans[i][j] = rows[i] | cols[j]
	return ans

def solve():
	(n, m) = vars()
	mat = []
	for i in range(n):
		mat.append(array())
	rows = [1 for i in range(n)]
	cols = [1 for i in range(m)]
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 0:
				rows[i] = 0
	for j in range(m):
		for i in range(n):
			if mat[i][j] == 0:
				cols[j] = 0
	ans = [[0 for i in range(m)] for j in range(n)]
	for i in range(n):
		for j in range(m):
			ans[i][j] = rows[i] & cols[j]
	if mat == check(ans, n, m):
		print('YES')
		for i in range(n):
			for j in range(m):
				print(ans[i][j], end=' ')
			print()
	else:
		print('NO')

def main():
	t = 1
	for _ in range(t):
		solve()

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def sieve():
	primes = [1 for i in range(MAX)]
	primes[0] = primes[1] = 0
	i = 2
	while i <= MAX ** 0.5:
		j = i * i
		while primes[i] and j < MAX:
			if j % i == 0:
				primes[j] = 0
			j += i
		i += 1
	return primes

def input():
	return sys.stdin.readline().rstrip('\n').strip()

def print(*args, sep=' ', end='\n'):
	first = True
	for arg in args:
		if not first:
			sys.stdout.write(str(sep))
		sys.stdout.write(str(arg))
		first = False
	sys.stdout.write(end)

def vars():
	return map(int, input().split())

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


(m, n) = map(int, input().split())
li = [list(map(int, input().split())) for i in range(m)]
ans = [[1] * n for i in range(m)]
for i in range(m):
	for j in range(n):
		if li[i][j] == 0:
			for k in range(n):
				ans[i][k] = 0
			for k in range(m):
				ans[k][j] = 0
flag = True
for i in range(m):
	for j in range(n):
		tp = ans[i][j]
		for k in range(m):
			tp = tp or ans[k][j]
		for k in range(n):
			tp = tp or ans[i][k]
		if li[i][j] != tp:
			flag = False
			break
if flag:
	print('YES')
	for i in ans:
		print(*i)
else:
	print('NO')


def main():
	(m, n) = [int(i) for i in input().split()]
	a = [[0] * n for _ in range(m)]
	b = [[int(i) for i in input().split()] for _ in range(m)]
	row_all_true = []
	for i in range(m):
		if all(b[i]):
			row_all_true.append(i)
	col_all_true = []
	for j in range(n):
		if all((b[i][j] for i in range(m))):
			col_all_true.append(j)
	for i in row_all_true:
		for j in col_all_true:
			a[i][j] = 1
	for i in range(m):
		for j in range(n):
			if b[i][j] and (not any(a[i])) and (not any((a[k][j] for k in range(m)))):
				print('NO')
				return
	print('YES')
	for row in a:
		print(*row)
main()


def solve(m, n, matrix):
	res = [[0] * n for _ in range(m)]
	for i in range(m):
		for j in range(n):
			if matrix[i][j]:
				check_row = all([matrix[i][x] for x in range(n)])
				check_column = all([matrix[x][j] for x in range(m)])
				if check_row and check_column:
					res[i][j] = 1
	check = [[0] * n for _ in range(m)]
	for i in range(m):
		for j in range(n):
			if res[i][j]:
				for x in range(m):
					check[x][j] = 1
				for x in range(n):
					check[i][x] = 1
	if check != matrix:
		return None
	return res
parse = lambda st: list(map(int, st.split()))
(m, n) = parse(input())
res = solve(m, n, [parse(input()) for _ in range(m)])
if not res:
	print('NO')
else:
	print('YES')
	for i in range(m):
		print(' '.join(map(str, res[i])))


(m, n) = [int(x) for x in input().split()]
l = []
for i in range(m):
	l.append([int(x) for x in input().split()])
suml = 0
for i in l:
	suml += sum(i)
flag3 = 1
ans = [[0] * n for i in range(m)]
for i in range(m):
	for j in range(n):
		if l[i][j] == 1:
			flag1 = flag2 = 1
			for k in range(m):
				if l[k][j] == 0:
					flag1 = 0
					break
			for p in range(n):
				if l[i][p] == 0:
					flag2 = 0
					break
			if flag1 == 1 and flag2 == 1:
				ans[i][j] = 1
			if flag1 == 0 and flag2 == 0:
				flag3 = 0
flag = 0
for i in range(m):
	for j in range(n):
		if ans[i][j] == 1:
			flag = 1
			break
if m == 1 and n == 1 and (l[0][0] == 0):
	print('YES')
	print(0)
elif (flag or (not flag and suml == 0)) and flag3:
	print('YES')
	for i in range(m):
		for j in range(n):
			print(ans[i][j], end=' ')
		print()
else:
	print('NO')


(m, n) = map(int, input().split())
b = []
a = [[1] * n] * m
for i in range(m):
	b.append(list(map(int, input().split())))
for i in range(m):
	for j in range(n):
		if b[i][j] == 0:
			a[i] = [0] * n
			for k in range(m):
				a[k][j] = 0
for i in range(m):
	for j in range(n):
		f = 0
		for k in range(m):
			if a[k][j] == 1:
				f = 1
				break
		for k in range(n):
			if a[i][k] == 1:
				f = 1
				break
		if f and b[i][j] == 0:
			print('NO')
			exit()
		elif f == 0 and b[i][j]:
			print('NO')
			exit()
print('YES')
for item in a:
	print(*item)


(n, m) = [int(x) for x in input().split()]
mat = []
mat1 = []
for x in range(n):
	l = [int(z) for z in input().split()]
	mat.append(l)
	l1 = [0 for x in range(m)]
	mat1.append(l1)
rsum = []
for x in range(n):
	su = 0
	for y in range(m):
		su = su + mat[x][y]
	if su == m:
		su = 1
	else:
		su = 0
	rsum.append(su)
s = sum(rsum)
csum = []
for x in range(m):
	su = 0
	for y in range(n):
		su = su + mat[y][x]
	if su == n:
		su = 1
	else:
		su = 0
	csum.append(su)
s1 = sum(csum)
flag = 0
for x in range(n):
	for y in range(m):
		val = mat[x][y]
		a = rsum[x]
		b = csum[y]
		if val == 0 and (rsum[x] > 0 or csum[y] > 0):
			flag = 1
			break
		elif val == 1 and (rsum[x] == 0 and csum[y] == 0):
			flag = 1
			break
		elif s == 0 and s1 > 0:
			flag = 1
			break
		elif s > 0 and s1 == 0:
			flag = 1
			break
		else:
			mat1[x][y] = min(rsum[x], csum[y])
	if flag == 1:
		print('NO')
		break
if flag == 0:
	print('YES')
	for x in range(n):
		for y in range(m):
			print(mat1[x][y], end=' ')
		print()


(m, n) = [int(x) for x in input().split()]
B = []
for i in range(m):
	B.append([int(x) for x in input().split()])
A = [[1] * n for x in range(m)]
for i in range(m):
	for j in range(n):
		if B[i][j] == 0:
			for x in range(m):
				A[x][j] = 0
			for x in range(n):
				A[i][x] = 0
fl = True
for i in range(m):
	for j in range(n):
		if B[i][j] == 1:
			if 1 not in [A[x][j] for x in range(m)] and 1 not in [A[i][x] for x in range(n)]:
				fl = False
if fl:
	print('YES')
	for i in range(m):
		print(' '.join([str(x) for x in A[i]]))
else:
	print('NO')


(m, n) = map(int, input().split(' '))
raw = [list(map(int, input().split(' '))) for _ in range(m)]
restorated = [[-1 for __ in range(n)] for _ in range(m)]
for i in range(m):
	for j in range(n):
		if raw[i][j] == 0:
			for ii in range(m):
				restorated[ii][j] = 0
			for jj in range(n):
				restorated[i][jj] = 0
flag = True
for i in range(m):
	flag = True
	for j in range(n):
		if raw[i][j] == 1:
			flag = False
			for ii in range(m):
				flag = flag or restorated[ii][j] != 0
			for jj in range(n):
				flag = flag or restorated[i][jj] != 0
		if not flag:
			print('NO')
			break
	if not flag:
		break
if flag:
	print('YES')
	for row in restorated:
		for el in row:
			print(-el, end=' ')
		print()


(m, n) = list(map(int, input().split()))
mat = []
for _ in range(m):
	mat.append(list(map(int, input().split())))
row = set()
col = set()
for i in range(m):
	for j in range(n):
		if mat[i][j] == 0:
			row.add(i)
			col.add(j)
A = [[1] * n for i in range(m)]
for i in range(m):
	for j in range(n):
		if i in row or j in col:
			A[i][j] = 0
row = set()
col = set()
for i in range(m):
	for j in range(n):
		if A[i][j] == 1:
			row.add(i)
			col.add(j)
flag = True
for i in range(m):
	for j in range(n):
		if mat[i][j] == 1:
			if i in row or j in col:
				pass
			else:
				flag = False
				break
if flag:
	print('YES')
	for r in A:
		print(*r)
else:
	print('NO')


(n, m) = map(int, input().split())
t = [[1] * m for i in range(n)]
s = [[0] * m for i in range(n)]
p = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	for j in range(m):
		if p[i][j] == 0:
			for k in range(n):
				t[k][j] = 0
			for k in range(m):
				t[i][k] = 0
for i in range(n):
	for j in range(m):
		if t[i][j] == 1:
			for k in range(n):
				s[k][j] = 1
			for k in range(m):
				s[i][k] = 1
for i in range(n):
	for j in range(m):
		if p[i][j] == 1:
			if s[i][j] == 0:
				print('NO')
				exit()
print('YES')
for i in range(n):
	print(' '.join(map(str, t[i])))


(m, n) = map(int, input().split())
l = []
l1 = []
for i in range(m):
	l.append(list(map(int, input().split())))
	l1.append([0] * n)
lr = [1] * m
lc = [1] * n
for i in range(m):
	for j in range(n):
		if l[i][j] == 0:
			lr[i] = 0
			lc[j] = 0
lr1 = [0] * m
lc1 = [0] * n
for i in range(m):
	for j in range(n):
		if lr[i] == 1 and lc[j] == 1:
			l1[i][j] = 1
			lr1[i] = 1
			lc1[j] = 1
flag = True
for i in range(m):
	for j in range(n):
		if l[i][j] == 1 and lr1[i] == 0 and (lc1[j] == 0):
			flag = False
			break
	if flag == False:
		break
if flag == True:
	print('YES')
	for i in range(m):
		print(*l1[i])
else:
	print('NO')


import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(' '))
from math import factorial

def cross_fill(i, j, m, n, matrix, value):
	for idx in range(m):
		matrix[idx][j] = value
	for idx in range(n):
		matrix[i][idx] = value

def _or(i, j, m, n, matrix):
	res = 0
	for idx in range(m):
		res += matrix[idx][j]
	for idx in range(n):
		res += matrix[i][idx]
	return int(res > 0)

def create_B(matrix, m, n):
	res = [[None for _ in range(n)] for _ in range(m)]
	for i in range(m):
		for j in range(n):
			res[i][j] = _or(i, j, m, n, matrix)
	return res

def solve():
	(m, n) = read_tuple(int)
	B = [list(read_tuple(int)) for _ in range(m)]
	A = [[1 for _ in range(n)] for _ in range(m)]
	for i in range(m):
		for j in range(n):
			if B[i][j] == 0:
				cross_fill(i, j, m, n, A, 0)
	reproduced_B = create_B(A, m, n)
	if B == reproduced_B:
		print('YES')
		for row in A:
			print(' '.join(map(str, row)))
	else:
		print('NO')
solve()


(x, y) = map(int, input().split())
lol = []
for __ in range(x):
	lol.append(list(map(int, input().split())))
yo = []
for i in lol:
	po = i[:]
	yo.append(po)
for i in range(x):
	k = 1
	for j in range(y):
		k &= lol[i][j]
	for j in range(y):
		yo[i][j] &= k
for i in range(y):
	k = 1
	for j in range(x):
		k &= lol[j][i]
	for j in range(x):
		yo[j][i] &= k
yo0 = []
for i in yo:
	po = i[:]
	yo0.append(po)
for i in range(x):
	k = 0
	for j in range(y):
		k |= yo[i][j]
	for j in range(y):
		yo0[i][j] |= k
for i in range(y):
	k = 0
	for j in range(x):
		k |= yo[j][i]
	for j in range(x):
		yo0[j][i] |= k
if yo0 == lol:
	print('YES')
	for i in yo:
		print(*i)
else:
	print('NO')


(m, n) = list(map(int, input().split()))
A = []
for i in range(m):
	A.append(['1'] * n)
B = []
for i in range(m):
	B.append(input().split())
for i in range(len(B)):
	for j in range(len(B[i])):
		if B[i][j] == '0':
			for k1 in range(m):
				A[k1][j] = '0'
			for k1 in range(n):
				A[i][k1] = '0'
flag = False
for i in range(m):
	for j in range(n):
		elem = 0
		for k1 in range(m):
			elem = elem or int(A[k1][j])
		for k1 in range(n):
			elem = elem or int(A[i][k1])
		if B[i][j] != str(elem):
			flag = True
if flag:
	print('NO')
else:
	print('YES')
	for i in range(m):
		print(' '.join(A[i]))


[n, m] = [int(x) for x in input().split()]
matrix = []
for _ in range(n):
	l = [int(x) for x in input().split()]
	matrix.append(l)

def operation_or(l):
	row_op = []
	col_op = []
	output = []
	for i in range(n):
		temp = 1
		for j in range(m - 1):
			temp = temp and matrix[i][j] and matrix[i][j + 1]
		row_op.append(temp)
	for j in range(m):
		temp = 1
		for i in range(n - 1):
			temp = temp and matrix[i][j] and matrix[i + 1][j]
		col_op.append(temp)
	for i in range(n):
		temp = []
		for j in range(m):
			temp.append(row_op[i] and col_op[j])
		output.append(temp)
	return output

def operation_and(l):
	row_op = []
	col_op = []
	output = []
	for i in range(n):
		temp = 0
		for j in range(m - 1):
			temp = temp or l[i][j] or l[i][j + 1]
		row_op.append(temp)
	for j in range(m):
		temp = 0
		for i in range(n - 1):
			temp = temp or l[i][j] or l[i + 1][j]
		col_op.append(temp)
	for i in range(n):
		temp = []
		for j in range(m):
			temp.append(row_op[i] or col_op[j])
		output.append(temp)
	return output
if n != 1 or m != 1:
	output = operation_or(matrix)
	op_cmp = operation_and(output)
	flag = False
	for (i, j) in zip(op_cmp, matrix):
		for (q, k) in zip(i, j):
			if q != k:
				flag = True
				break
	if flag == True:
		print('NO')
	if flag != True:
		print('YES')
		for i in output:
			for j in i:
				print(j, end=' ')
			print()
else:
	print('YES')
	print(matrix[0][0])


import copy
(m, n) = map(int, input().split())
mat = [list(map(int, input().split())) for x in range(m)]
mat2 = copy.deepcopy(mat)
matResp = [[0 for x in range(n)] for x in range(m)]

def checkAllDirFull(i, j):
	global mat
	aux = j + 1
	while aux < n:
		if mat[i][aux] == 0:
			return False
		aux += 1
	aux = j - 1
	while aux >= 0:
		if mat[i][aux] == 0:
			return False
		aux -= 1
	aux = i + 1
	while aux < m:
		if mat[aux][j] == 0:
			return False
		aux += 1
	aux = i - 1
	while aux >= 0:
		if mat[aux][j] == 0:
			return False
		aux -= 1
	return True

def change(i, j):
	global mat, mat2, matResp
	matResp[i][j] = 1
	mat2[i][j] = 2
	aux = j + 1
	while aux < n:
		mat2[i][aux] = 2
		aux += 1
	aux = j - 1
	while aux >= 0:
		mat2[i][aux] = 2
		aux -= 1
	aux = i + 1
	while aux < m:
		mat2[aux][j] = 2
		aux += 1
	aux = i - 1
	while aux >= 0:
		mat2[aux][j] = 2
		aux -= 1

def process():
	global mat
	for i in range(m):
		for j in range(n):
			if mat[i][j] == 1:
				if checkAllDirFull(i, j):
					change(i, j)

def check():
	for i in range(m):
		for j in range(n):
			if mat2[i][j] == 1:
				return False
	return True

def printMat(matrix):
	if len(matrix[0]) == 1:
		for i in range(len(matrix)):
			for j in range(len(matrix[0])):
				print(matrix[i][j])
	else:
		for i in range(len(matrix)):
			for j in range(len(matrix[0]) - 1):
				print(matrix[i][j], end=' ')
			print(matrix[i][j + 1], end='\n')
process()
if check():
	print('YES')
	printMat(matResp)
else:
	print('NO')


import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))
temparr = get_ints()
r = int(temparr[0])
c = int(temparr[1])
arr = []
rowfull = []
flag = 0
temparr = [-1 for _ in range(c)]
ans = [temparr[:] for _ in range(r)]
for i in range(r):
	newinput = get_ints()
	arr.append(newinput[:])
	for j in range(c):
		if newinput[j] == 0:
			for k in range(c):
				ans[i][k] = 0
			for k in range(r):
				ans[k][j] = 0
flag = 0
for i in range(r):
	for j in range(c):
		flag = 0
		if arr[i][j] == 1:
			for k in range(c):
				if ans[i][k] == -1 or ans[i][k] == 1:
					ans[i][k] = 1
					flag = 1
			for k in range(r):
				if ans[k][j] == -1 or ans[k][j] == 1:
					ans[k][j] = 1
					flag = 1
			if flag == 0:
				flag = 2
				break
		if flag == 2:
			break
	if flag == 2:
		break
if flag == 2:
	print('NO')
else:
	print('YES')
	for i in range(r):
		strs = ''
		for j in range(c):
			strs += str(ans[i][j])
			strs += ' '
		print(strs)


(m, n) = map(int, input().split())
a = []
for i in range(m):
	x = list(map(int, input().split()))
	a.append(x)
b = []
for i in range(m):
	b.append([1] * n)
for i in range(m):
	for j in range(n):
		if a[i][j] == 0:
			for k in range(n):
				b[i][k] = 0
			for k in range(m):
				b[k][j] = 0
for i in range(m):
	for j in range(n):
		t = 0
		for k in range(n):
			t |= b[i][k]
		for k in range(m):
			t |= b[k][j]
		if t != a[i][j]:
			print('NO')
			exit()
print('YES')
for i in range(m):
	f = ''
	for j in range(n):
		f += str(b[i][j]) + ' '
	print(f)


def solve(A, n, m):
	rows = {}
	col = {}
	if n == 1 and m == 1:
		return (True, A)
	sm = False
	for i in range(n):
		s = 0
		for j in range(m):
			if A[i][j] == 1:
				sm = True
				s += 1
		rows[i] = s
	for i in range(m):
		s = 0
		for j in range(n):
			if A[j][i] == 1:
				s += 1
		col[i] = s
	B = [[0 for x in range(m)] for y in range(n)]
	flag = 0
	ones = 0
	for i in range(n):
		for j in range(m):
			if A[i][j] == 1:
				flag = 1
				if rows[i] == m and col[j] == n:
					B[i][j] = 1
					ones = 1
				elif rows[i] < m and col[j] < n:
					return (False, [])
	if flag and ones:
		return (True, B)
	else:
		if not sm:
			return (True, A)
		return (False, [])

def printMat(Mat):
	for i in Mat:
		for j in i:
			print(j, end=' ')
		print()
(N, M) = map(int, input().split())
A = []
for i in range(N):
	A.append(list(map(int, input().split())))
(flag, mat) = solve(A, N, M)
if flag:
	print('YES')
	printMat(mat)
else:
	print('NO')


import os
import sys
from io import BytesIO, IOBase
mod = 10 ** 9 + 7

def changetozero(a, i, j, r, c):
	for z in range(r):
		a[z][j] = 0
	for z in range(c):
		a[i][z] = 0
	return

def checkone(a, i, j, r, c):
	for z in range(r):
		if a[z][j] == 1:
			return 1
	for z in range(c):
		if a[i][z] == 1:
			return 1
	return 0

def main():
	(r, c) = map(int, input().split())
	a = [[1 for _ in range(c)] for _ in range(r)]
	b = []
	for _ in range(r):
		b.append(list(map(int, input().split())))
	for i in range(r):
		for j in range(c):
			if b[i][j] == 0:
				changetozero(a, i, j, r, c)
	for i in range(r):
		for j in range(c):
			if b[i][j] == 1:
				if checkone(a, i, j, r, c):
					pass
				else:
					print('NO')
					exit()
	print('YES')
	for item in a:
		print(*item)

def nouse0():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse1():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse2():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
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')

def nouse3():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse4():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse5():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
main()


def printGrid(grid):
	for row in grid:
		print(' '.join(list(map(str, row))))
(n, m) = map(int, input().strip().split())
grid = [list(map(int, input().strip().split())) for _ in range(n)]
ans = [[-1] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		if grid[i][j] == 0:
			for x in range(n):
				ans[x][j] = 0
			for y in range(m):
				ans[i][y] = 0
for i in range(n):
	for j in range(m):
		if ans[i][j] == -1:
			ans[i][j] = 1
gen = [[0] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		curr = 0
		for x in range(n):
			curr |= ans[x][j]
		for y in range(m):
			curr |= ans[i][y]
		gen[i][j] = curr
if gen == grid:
	print('YES')
	printGrid(ans)
else:
	print('NO')


(m, n) = [int(i) for i in input().split()]
b = [[int(i) for i in input().split()] for j in range(m)]
a = [[1] * n for i in range(m)]
for i in range(m):
	for j in range(n):
		if b[i][j] == 0:
			for k in range(n):
				a[i][k] = 0
			for k in range(m):
				a[k][j] = 0
for i in range(m):
	for j in range(n):
		if b[i][j] == 1:
			if not [a[i][k] for k in range(n)].count(1) and (not [a[k][j] for k in range(m)].count(1)):
				print('NO')
				exit()
else:
	print('YES')
	for i in range(m):
		print(' '.join([str(j) for j in a[i]]))


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.setrecursionlimit(int(pow(10, 6)))
	sys.stdin = open('input.txt', 'r')
except:
	pass
(n, m) = L()
A = [L() for i in range(n)]
r = [i for i in range(n)]
c = [i for i in range(m)]
r = set(r)
c = set(c)
p1 = 0
for i in range(n):
	for j in range(m):
		if A[i][j]:
			p1 = 1
		else:
			if i in r:
				r.discard(i)
			if j in c:
				c.discard(j)
for i in range(n):
	for j in range(m):
		if A[i][j] == 1 and (i not in r and j not in c):
			print('NO')
			exit()
if (len(r) == 0 or len(c) == 0) and p1 == 1:
	print('NO')
elif (len(r) == 0 or len(c) == 0) and p1 == 0:
	print('YES')
	for i in range(n):
		print(*A[i])
else:
	print('YES')
	for i in range(n):
		for j in range(m):
			if i in r and j in c:
				A[i][j] = 1
			else:
				A[i][j] = 0
		print(*A[i])
endtime = time.time()


(n, m) = map(int, input().split())
b = []
for i in range(n):
	b.append([int(i) for i in input().split()])
note = []
a = [[1 for j in range(m)] for i in range(n)]
for i in range(n):
	for j in range(m):
		if b[i][j] == 0:
			note.append([i, j])
for ind in range(len(note)):
	i = note[ind][0]
	j = note[ind][1]
	for x in range(n):
		a[x][j] = 0
	for x in range(m):
		a[i][x] = 0
note = []
a1 = [[0 for j in range(m)] for i in range(n)]
for i in range(n):
	for j in range(m):
		a1[i][j] = a[i][j]
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			note.append([i, j])
for ind in range(len(note)):
	i = note[ind][0]
	j = note[ind][1]
	for x in range(n):
		a1[x][j] = 1
	for x in range(m):
		a1[i][x] = 1
if a1 == b:
	print('YES')
	for i in range(n):
		print(*a[i])
else:
	print('NO')


(m, n) = [int(x) for x in input().split()]
l = []
for i in range(m):
	l.append([int(x) for x in input().split()])
ans = [[1] * n for i in range(m)]
for i in range(m):
	for j in range(n):
		if l[i][j] == 0:
			for p in range(n):
				ans[i][p] = 0
			for q in range(m):
				ans[q][j] = 0
flag = 1
for i in range(m):
	for j in range(n):
		if l[i][j] == 1:
			flag = 0
			for p in range(n):
				if ans[i][p] == 1:
					flag = 1
					break
			if flag == 0:
				for q in range(m):
					if ans[q][j] == 1:
						flag = 1
						break
		if flag == 0:
			break
	if flag == 0:
		print('NO')
		break
if flag:
	print('YES')
	for i in range(m):
		for j in range(n):
			print(ans[i][j], end=' ')
		print()


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, m) = get_ints()
mat = []
for i in range(n):
	mat.append(get_array())
ans = [[0 for i in range(m)] for j in range(n)]
count1 = 0
count2 = 0
for i in range(n):
	for j in range(m):
		if mat[i][j] == 1:
			flag = 0
			for k in range(m):
				if mat[i][k] != 1:
					flag += 1
					break
			for k in range(n):
				if mat[k][j] != 1:
					flag += 1
					break
			if flag > 1:
				print('NO')
				exit()
			if flag == 1:
				count1 += 1
			elif flag == 0:
				ans[i][j] = 1
				count2 += 1
if count1 > 0 and count2 == 0:
	print('NO')
else:
	print('YES')
	for i in ans:
		print(*i)


(rows, columns) = map(int, input().strip().split(' '))
new_matrix = [[1] * columns for _ in range(rows)]
old_matrix = []
check_matrix = [[0] * columns for _ in range(rows)]
for i in range(rows):
	old_matrix.append(list(map(int, input().strip().split(' '))))
for i in range(rows):
	for j in range(columns):
		if old_matrix[i][j] == 0:
			for k in range(columns):
				new_matrix[i][k] = 0
			for k in range(rows):
				new_matrix[k][j] = 0
for i in range(rows):
	for j in range(columns):
		if 1 in new_matrix[i]:
			check_matrix[i][j] = 1
			continue
		else:
			for k in range(rows):
				if new_matrix[k][j] == 1:
					check_matrix[i][j] = 1
					break
if old_matrix == check_matrix:
	print('YES')
	for element in new_matrix:
		print(' '.join(list(map(str, element))))
else:
	print('NO')


(n, m) = map(int, input().split())
x = []
xi = []
xj = []
c = True
d = False
e = False
for i in range(n):
	xi.append(True)
for i in range(m):
	xj.append(True)
for i in range(n):
	y = []
	l = list(map(int, input().split()))
	for j in range(m):
		y.append(l[j])
		if l[j] == 0:
			xi[i] = False
			xj[j] = False
		else:
			e = True
	x.append(y)
for i in range(n):
	for j in range(m):
		if x[i][j] == 1:
			if xi[i] and xj.count(True) > 0:
				pass
			elif xj[j] and xi.count(True) > 0:
				pass
			else:
				c = False
				break
	if c == False:
		break
s = []
for i in range(n):
	t = []
	for j in range(m):
		if xi[i] and xj[j]:
			t.append(1)
			d = True
		else:
			t.append(0)
	s.append(t)
if c:
	print('YES')
	for i in s:
		for j in i:
			print(j, end=' ')
		print()
else:
	print('NO')


def check(ans, n, m):
	temp = [[0 for i in range(m)] for j in range(n)]
	for i in range(n):
		for j in range(m):
			if ans[i][j] == 1:
				temp[i] = [1] * m
				for p in range(n):
					temp[p][j] = 1
	return temp

def main():
	(n, m) = map(int, input().split())
	a = [list(map(int, input().split())) for i in range(n)]
	ans = [[1 for i in range(m)] for j in range(n)]
	for i in range(n):
		for j in range(m):
			if a[i][j] == 0:
				ans[i] = [0] * m
				for p in range(n):
					ans[p][j] = 0
	if check(ans, n, m) == a:
		print('YES')
		for i in range(n):
			print(*ans[i])
	else:
		print('NO')
main()


(n, m) = map(int, input().split())
tab = [[int(i) for i in input().split()] for j in range(n)]
ans = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	for j in range(m):
		z = 1
		for k in tab[i]:
			z = z and k
		for k in range(n):
			z = z and tab[k][j]
		ans[i][j] = z
tr = True
for i in range(n):
	for j in range(m):
		z = 0
		for k in ans[i]:
			z = z or k
		for k in range(n):
			z = z or ans[k][j]
		if z != tab[i][j] and tr:
			tr = False
			print('NO')
if tr:
	print('YES')
	for s in ans:
		for x in s:
			print(x, end=' ')
		print()


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
b = []
for i in range(n):
	b.append([0] * m)

def fill(x, y):
	for i in range(n):
		b[i][y] = 1
	for i in range(m):
		b[x][i] = 1

def getv(c, x, y):
	res = False
	for i in range(n):
		res = res or c[i][y]
	for i in range(m):
		res = res or c[x][i]
	return res

def getv2(c, x, y):
	res = True
	for i in range(n):
		res = res and c[i][y]
	for i in range(m):
		res = res and c[x][i]
	return res
for i in range(n):
	for j in range(m):
		if getv2(a, i, j):
			b[i][j] = 1
good = True
for i in range(n):
	for j in range(m):
		if a[i][j] != getv(b, i, j):
			good = False
if good == False:
	print('NO')
else:
	print('YES')
	for i in range(n):
		for j in range(m - 1):
			print(b[i][j], end=' ')
		print(b[i][m - 1])


(n, m) = [int(x) for x in input().split()]
bmatrix = []
for i in range(n):
	bmatrix.append(input().split())
amatrix = [['1' for x in range(m)] for x in range(n)]
zerorows = []
zerocols = []
for i in range(n):
	for j in range(m):
		if bmatrix[i][j] == '0':
			zerorows.append(i)
			zerocols.append(j)
for i in zerorows:
	for j in range(m):
		amatrix[i][j] = '0'
for j in zerocols:
	for i in range(n):
		amatrix[i][j] = '0'
rows = []
for i in range(n):
	rowor = 0
	for j in range(m):
		rowor |= int(amatrix[i][j])
	rows.append(rowor)
cols = []
for j in range(m):
	color = 0
	for i in range(n):
		color |= int(amatrix[i][j])
	cols.append(color)
flg = False
for i in range(n):
	for j in range(m):
		if rows[i] | cols[j] != int(bmatrix[i][j]):
			print('NO')
			flg = True
			break
	if flg:
		break
else:
	print('YES')
	for x in amatrix:
		print(*x)