Little Elephant loves magic squares very much.

A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. $\left. \begin{array}{|c|c|c|} \hline 4 & {9} & {2} \\ \hline 3 & {5} & {7} \\ \hline 8 & {1} & {6} \\ \hline \end{array} \right.$ 

The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 10^5. 

Help the Little Elephant, restore the original magic square, given the Elephant's notes.


-----Input-----

The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes.

It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 10^5.


-----Output-----

Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 10^5.

It is guaranteed that there exists at least one magic square that meets the conditions.


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

Output
1 1 1
1 1 1
1 1 1

Input
0 3 6
5 0 5
4 7 0

Output
6 3 6
5 5 5
4 7 4

Source: codeforces | Difficulty: EASY
Tags: Implementation

Complete search


Solutions:
(a, b, c) = [int(x) for x in input().split()]
(d, e, f) = [int(x) for x in input().split()]
(g, h, i) = [int(x) for x in input().split()]
print((h + f) // 2, b, c)
print(d, (g + c) // 2, f)
print(g, h, (d + b) // 2)


mat = []
for i in range(3):
	mat.append([int(i) for i in input().split()])
a = mat[0][1] + mat[0][2]
b = mat[1][0] + mat[1][2]
c = mat[2][0] + mat[2][1]

def check(x):
	z = x - a
	y = x - b
	k = x - c
	return y + z + k == x
for i in range(0, 3 * 10 ** 5 + 1, 3):
	if check(i):
		ans = i
		break
mat[0][0] = ans - a
mat[1][1] = ans - b
mat[2][2] = ans - c
for i in range(3):
	print(*mat[i])


arr = []
l = []
for i in range(3):
	arr.append([])
	arr[i] = [int(i) for i in input().split()]
	l.append(sum(arr[i]))
s = sum(l) // 2
arr[0][0] = s - l[0]
arr[1][1] = s - l[1]
arr[2][2] = s - l[2]
for i in arr:
	for j in i:
		print(j, end=' ')
	print()


sq = []
i = 0
while i < 3:
	row = [int(x) for x in input().split()]
	sq.append(row)
	i += 1
eq1 = sum(sq[1]) - sum(sq[0])
eq2 = sum(sq[2])
sq[0][0] = (eq1 + eq2) // 2
sq[1][1] = sum(sq[0]) - sum(sq[1])
sq[2][2] = sum(sq[0]) - sum(sq[2])
for i in range(3):
	for j in range(3):
		if j == 2:
			print(sq[i][j])
		else:
			print(sq[i][j], end=' ')


(a, b, c) = map(int, input().split())
(d, e, f) = map(int, input().split())
(g, h, i) = map(int, input().split())
a = g + (h - b) / 2
i = c + (b - h) / 2
e = b + c - i
print(int(a), ' ', b, ' ', c)
print(d, ' ', int(e), ' ', f)
print(g, ' ', h, ' ', int(i))


import sys
row1 = list(map(int, sys.stdin.readline().strip().split(' ')))
row2 = list(map(int, sys.stdin.readline().strip().split(' ')))
row3 = list(map(int, sys.stdin.readline().strip().split(' ')))
rows = [row1, row2, row3]
s1 = sum(row1)
s2 = sum(row2)
s3 = sum(row3)

def P(row, ix, num):
	if ix == 0:
		print('{} {} {}'.format(num, row[1], row[2]))
	elif ix == 1:
		print('{} {} {}'.format(row[0], num, row[2]))
	else:
		print('{} {} {}'.format(row[0], row[1], num))
z = (s2 + s1 - s3) // 2
y = s1 - z
x = s3 - y
vals = [x, y, z]
for (ix, r) in enumerate(rows):
	P(r, ix, vals[ix])


class CodeforcesTask259BSolution:

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

	def read_input(self):
		for x in range(3):
			self.square.append([int(x) for x in input().split(' ')])

	def process_task(self):
		s = self.square
		s[0][0] = (s[1][0] + s[1][2] + s[2][0] + s[2][1] - s[0][1] - s[0][2]) // 2
		s[1][1] = s[2][0] + s[2][1] - s[0][0]
		s[2][2] = s[1][0] + s[1][2] - s[0][0]
		self.result = '{0}\n{1}\n{2}'.format(*[' '.join([str(y) for y in x]) for x in s])

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


sp = [list(map(int, input().split())) for i in range(3)]
(n1, n2, n3) = (sum(sp[0]), sum(sp[1]), sum(sp[2]))
for i in range(1, 10 ** 5 + 1):
	s = sp[0][1] + sp[0][2] + i
	(x1, x2, x3) = (s - n1, s - n2, s - n3)
	if x1 + x2 + x3 == s and x1 > 0 and (x2 > 0) and (x3 > 0):
		for j in range(3):
			for h in range(j):
				print(sp[j][h], end=' ')
			print(s - sum(sp[j]), end=' ')
			for h in range(j + 1, 3):
				print(sp[j][h], end=' ')
			print()
		break


A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
y = (A[1] + A[2] + (C[0] + C[1] - (B[0] + B[2]))) // 2
x = y + B[0] + B[2] - (A[1] + A[2])
z = y + B[0] + B[2] - (C[0] + C[1])
A[0] = x
B[1] = y
C[2] = z
print(A[0], A[1], A[2])
print(B[0], B[1], B[2])
print(C[0], C[1], C[2])


def mi():
	return map(int, input().split())
(q, w, e) = mi()
(a, s, d) = mi()
(z, x, c) = mi()
q = int((a + 2 * d - w) / 2)
s = e + d - q
c = e + s + z - q - s
print(q, w, e)
print(a, s, d)
print(z, x, c)


def solve(f, s, t):
	(f_tot, s_tot, t_tot) = (sum(f), sum(s), sum(t))
	get = (f_tot + s_tot + t_tot) // 2
	(f[0], s[1], t[2]) = (get - f_tot, get - s_tot, get - t_tot)
	print(*f)
	print(*s)
	print(*t)
f = list(map(int, input().split()))
s = list(map(int, input().split()))
t = list(map(int, input().split()))
solve(f, s, t)


l = []
for i in range(3):
	l.append(list(map(int, input().split())))
l[1][1] = (l[1][0] + l[1][2]) // 2
c = sum(l[1])
l[0][0] = c - (l[0][1] + l[0][2])
l[2][2] = c - (l[2][0] + l[2][1])
for i in range(3):
	for j in range(3):
		print(l[i][j], end=' ')
	print()


(x, d, e) = list(map(int, input().split()))
(a, y, f) = list(map(int, input().split()))
(b, c, z) = list(map(int, input().split()))
y = int((b + e) / 2)
z = y - b + d
x = z + c - a
print(x, d, e)
print(a, y, f)
print(b, c, z)


li = []
for i in range(3):
	minLi = list(map(int, input().split()))[:3]
	li.append(minLi)
s = 0
for i in range(3):
	s += sum(li[i])
half = s // 2
for i in range(3):
	indx = li[i].index(0)
	li[i][indx] = half - sum(li[i])
for i in range(3):
	print(*li[i], sep=' ')


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

def main():
	g = [read(), read(), read()]
	r = list(map(sum, g))
	s = sum(r) // 2
	for i in range(3):
		g[i][i] = s - r[i]
		print(*g[i])
main()


x = []
for i in range(3):
	x.append(list(map(int, input().split())))
(k, l) = (sum(x[0]), sum(x[2]))
if k < l:
	p = (l - k) // 2
	i = (l - 3 * p) // 2
	x[0][0] = i + 2 * p
	x[1][1] = i + p
	x[2][2] = i
elif k == l:
	x[0][0] = x[1][1] = x[2][2] = k // 2
else:
	p = (k - l) // 2
	i = (k - 3 * p) // 2
	x[0][0] = i
	x[1][1] = i + p
	x[2][2] = i + 2 * p
for i in range(3):
	print(*x[i])


l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
s = (sum(l) + sum(l1) + sum(l2)) // 2
print(s - sum(l), l[1], l[2])
print(l1[0], s - sum(l1), l1[2])
print(l2[0], l2[1], s - sum(l2))


from sys import stdin, stdout
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
arr = []
res = 0
for _ in range(3):
	t = iia()
	res += sum(t)
	arr.append(t)
res //= 2
arr[0][0] = res - arr[0][1] - arr[0][2]
arr[1][1] = res - arr[1][0] - arr[1][2]
arr[2][2] = res - arr[2][0] - arr[2][1]
for i in arr:
	print(*i, sep=' ')


a = []
for i in range(3):
	a.append(list(map(int, input().split())))
p = sum(a[2]) - sum(a[0])
q = a[0][2] + a[2][0]
a[0][0] = (p + q) // 2
a[2][2] = q - a[0][0]
a[1][1] = sum(a[0]) - sum(a[1])
for i in range(3):
	print('%d %d %d' % (a[i][0], a[i][1], a[i][2]))


3

def readln():
	return tuple(map(int, input().split()))
s = [list(readln()) for _ in range(3)]
for x in range(1, 10 ** 5 + 1):
	ss = x + s[0][1] + s[0][2]
	y = ss - s[1][0] - s[1][2]
	z = ss - s[2][0] - s[2][1]
	if x + y + z == ss:
		s[0][0] = x
		s[1][1] = y
		s[2][2] = z
		for _ in s:
			print(*tuple(_))


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()

def is_balanced(mat):
	tt = sum(mat[0])
	if sum(mat[1]) != tt:
		return False
	if sum(mat[2]) != tt:
		return False
	if mat[0][0] + mat[1][1] + mat[2][2] != tt:
		return False
	if mat[0][2] + mat[1][1] + mat[2][0] != tt:
		return False
	zip(*mat)
	if sum(mat[0]) != tt:
		return False
	if sum(mat[1]) != tt:
		return False
	if sum(mat[2]) != tt:
		return False
	return True
mat = []
for i in range(3):
	mat.append(get_array())
for i in range(0, 100005):
	mat[0][0] = i
	mat[1][1] = mat[0][0] + mat[0][2] - mat[2][1]
	mat[2][2] = mat[0][0] + mat[0][1] - mat[1][2]
	if is_balanced(mat):
		for i in mat:
			print(*i)
		exit()


(a, b, c) = input().split()
(d, e, f) = input().split()
(g, h, i) = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
e = int(e)
f = int(f)
g = int(g)
h = int(h)
i = int(i)
w = (a + b + c + d + e + f + g + h + i) / 2
a = int(w - b - c)
e = int(w - d - f)
i = int(w - g - h)
print(str(a) + ' ' + str(b) + ' ' + str(c))
print(str(d) + ' ' + str(e) + ' ' + str(f))
print(str(g) + ' ' + str(h) + ' ' + str(i))


def arr_inp():
	return [int(x) for x in input().split()]
arr = [arr_inp() for i in range(3)]
arr[2][2] = (arr[0][2] + arr[2][0] - (arr[2][0] + arr[2][1] - (arr[0][1] + arr[0][2]))) // 2
arr[0][0] = arr[2][2] + arr[2][0] + arr[2][1] - (arr[0][1] + arr[0][2])
arr[1][1] = arr[2][2] + arr[2][0] + arr[2][1] - (arr[1][0] + arr[1][2])
for i in range(3):
	print(*arr[i])


from __future__ import division, print_function
import math
import os
import sys
from sys import stdin, stdout
from io import BytesIO, IOBase
from collections import deque
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	l = []
	p = []
	g = []
	c = 0
	for i in range(3):
		arr = list(map(int, input().split()))
		p.append(arr)
		for i in arr:
			g.append(i)
		sum1 = sum(arr)
		l.append(sum1)
	max1 = max(l)
	for i in range(max1, max1 + 10 ** 5 + 3):
		if i - l[0] + (i - l[1]) + (i - l[2]) == i:
			c = i
			break
	p[0][0] = c - l[0]
	p[1][1] = c - l[1]
	p[2][2] = c - l[2]
	for i in range(len(p)):
		for j in range(len(p)):
			print(p[i][j], end=' ')
		print()
main()


a = []
for i in range(3):
	a.append(list(map(int, input().split())))
for n in range(1, 10 ** 5 + 1):
	s = n + a[0][1] + a[0][2]
	k = s - a[1][0] - a[1][2]
	w = s - a[2][0] - a[2][1]
	if n + k + w == s:
		a[0][0] = n
		a[1][1] = k
		a[2][2] = w
		break
for i in range(3):
	print(*a[i])


grid = [list(map(int, input().split())) for _ in range(3)]
t_1 = grid[0][1] + grid[0][2]
t_2 = grid[1][0] + grid[1][2]
t_3 = grid[2][0] + grid[2][1]
a = int((t_3 + t_2 - t_1) / 2)
c = int(t_2 - a)
b = int(t_1 - c)
grid[0][0] = a
grid[1][1] = b
grid[2][2] = c
for i in range(3):
	for j in range(3):
		print(grid[i][j], end=' ')
	print()


li1 = list(map(int, input().split()))
li2 = list(map(int, input().split()))
li3 = list(map(int, input().split()))
li = [li1] + [li2] + [li3]
for x in range(10 ** 6):
	li[0][0] = x
	a = sum(li[0])
	li[1][1] = a - li[1][0] - li[1][2]
	li[2][2] = a - li[2][0] - li[2][1]
	if li[0][0] + li[1][1] + li[2][2] == a and li[0][2] + li[1][1] + li[2][0] == a and (sum(li[0]) == a) and (sum(li[1]) == a) and (sum(li[2]) == a) and (li[0][0] + li[1][0] + li[2][0] == a) and (li[0][1] + li[1][1] + li[2][1] == a) and (li[0][2] + li[1][2] + li[2][2] == a):
		print('%d %d %d\n%d %d %d\n%d %d %d' % (li[0][0], li[0][1], li[0][2], li[1][0], li[1][1], li[1][2], li[2][0], li[2][1], li[2][2]))
		break


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
for i in range(1, 10 ** 5 + 9):
	l1[0] = i
	l2[1] = sum(l1) - l2[0] - l2[2]
	l3[2] = sum(l1) - l3[0] - l3[1]
	if l2[1] > 0 and l2[2] > 0:
		if sum(l1) == sum(l2) == sum(l3) == l1[0] + l2[0] + l3[0] == l1[1] + l2[1] + l3[1] == l1[2] + l2[2] + l3[2] == l1[0] + l2[1] + l3[2] == l1[2] + l2[1] + l3[0]:
			break
for i in l1:
	print(i, end=' ')
print()
for i in l2:
	print(i, end=' ')
print()
for i in l3:
	print(i, end=' ')


def main():
	l = [list(map(int, input().split())) for _ in range(3)]
	s = sum(map(sum, l)) // 2
	for (i, row) in enumerate(l):
		row[i] = s - sum(row)
		print(*row)
main()


a = []
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
x = sum(a[0])
y = sum(a[1])
z = sum(a[2])
a[1][1] = (z - (y - x)) // 2
a[0][0] = z - a[1][1]
a[2][2] = y - a[0][0]
for i in a:
	ans = ''
	for j in i:
		ans += str(j) + ' '
	print(ans)


def complete_magic_square(mag_sq):
	S = (mag_sq[0][1] + mag_sq[0][2] + mag_sq[1][0] + mag_sq[1][2] + mag_sq[2][0] + mag_sq[2][1]) // 2
	mag_sq[0][0] = S - (mag_sq[0][1] + mag_sq[0][2])
	mag_sq[1][1] = S - (mag_sq[1][0] + mag_sq[1][2])
	mag_sq[2][2] = S - (mag_sq[2][0] + mag_sq[2][1])
	return mag_sq
arr = []
for i in range(3):
	arr.append(list(map(int, input().split())))
result = complete_magic_square(arr)
for i in range(3):
	print(result[i][0], result[i][1], result[i][2], sep=' ')


a = []
for i in range(3):
	a.append([int(i) for i in input().split()])
sum_1 = sum(a[0])
sum_2 = sum(a[1])
sum_3 = sum(a[2])
z = (sum_1 + sum_2 - sum_3) // 2
y = sum_1 - z
x = sum_2 - z
a[0][0] = x
a[1][1] = y
a[2][2] = z
for i in range(3):
	for j in range(3):
		print(a[i][j], end=' ')
	print()


a = []
for i in range(3):
	a.append(list(map(int, input().split())))
a[1][1] = int((a[0][1] + a[0][2] + a[2][0] + a[2][1] - a[1][0] - a[1][2]) / 2)
a[0][0] = int(a[1][0] + a[1][1] + a[1][2] - a[0][1] - a[0][2])
a[2][2] = int(a[1][0] + a[1][1] + a[1][2] - a[2][1] - a[2][0])
for i in range(3):
	print(a[i][0], a[i][1], a[i][2])


row1 = [int(x) for x in input().split()]
row2 = [int(x) for x in input().split()]
row3 = [int(x) for x in input().split()]
sum1 = row1[1] + row1[2]
sum2 = row2[0] + row2[2]
sum3 = row3[1] + row3[0]
s = (sum1 + sum2 + sum3) // 2
row1[0] = s - sum1
row2[1] = s - sum2
row3[2] = s - sum3
for x in row1:
	print(x, end=' ')
print()
for x in row2:
	print(x, end=' ')
print()
for x in row3:
	print(x, end=' ')


s = []
for i in range(3):
	a = [int(x) for x in input().split()]
	s.append(a)
sum1 = s[0][0] + s[0][1] + s[0][2]
sum2 = s[1][0] + s[1][1] + s[1][2]
sum3 = s[2][0] + s[2][1] + s[2][2]
maxsum = (sum1 + sum2 + sum3) // 2
s[0][0] = maxsum - sum1
s[1][1] = maxsum - sum2
s[2][2] = maxsum - sum3
for i in range(3):
	for j in range(3):
		print(s[i][j], end=' ')
	print()


g = input()
(a1, a2, a3) = [int(x) for x in g.split()]
t = input()
(b1, b2, b3) = [int(x) for x in t.split()]
r = input()
(c1, c2, c3) = [int(x) for x in r.split()]
b = int((a2 + c2) / 2)
a = b + b1 + b3 - a2 - a3
c = b + b1 + b3 - c2 - c1
print(a, a2, a3)
print(b1, b, b3)
print(c1, c2, c)


mat = []
for _ in range(3):
	mat += [list(map(int, input().rstrip().split()))]
i = 0
while i <= 10 ** 5:
	mat[0][0] = i
	r1 = mat[0][0] + mat[0][1] + mat[0][2]
	c1 = mat[0][0] + mat[1][0] + mat[2][0]
	if r1 != c1:
		i += 1
	elif r1 - mat[0][1] - mat[2][1] != r1 - mat[1][0] - mat[1][2]:
		i += 1
	else:
		mat[1][1] = r1 - mat[0][1] - mat[2][1]
		if r1 - mat[2][1] - mat[2][0] != r1 - mat[0][2] - mat[1][2]:
			i += 1
		else:
			mat[2][2] = r1 - mat[2][1] - mat[2][0]
			if mat[0][0] + mat[1][1] + mat[2][2] == mat[2][0] + mat[1][1] + mat[0][2] == r1:
				break
			else:
				i += 1
for i in range(3):
	for j in range(3):
		print(mat[i][j], end=' ')
	print()


(x1, x2, x3) = map(int, input().split())
(x4, x5, x6) = map(int, input().split())
(x7, x8, x9) = map(int, input().split())
x5 = (x2 + x3 + x7 + x8 - x4 - x6) // 2
x1 = x5 + (x4 + x6 - x2 - x3)
x9 = x5 + (x4 + x6 - x7 - x8)
print(x1, x2, x3)
print(x4, x5, x6)
print(x7, x8, x9)


k = [list(map(int, input().split())) for x in range(3)]
k[0][0] = 1
k[1][1] = sum(k[0]) - sum(k[1])
k[2][2] = sum(k[0]) - sum(k[2])
s = k[0][1] + k[0][2]
x = min(k[0][0], k[1][1], k[2][2]) - 1
if x <= 0:
	k[0][0] -= x
	k[1][1] -= x
	k[2][2] -= x
while k[1][1] + k[2][2] != s:
	k[0][0] += 1
	k[1][1] += 1
	k[2][2] += 1
for i in k:
	for j in i:
		print(j, end=' ')
	print()


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())

def solve(mat):
	sm = (sum(mat[0]) + sum(mat[1]) + sum(mat[2])) // 2
	mat[0][0] = sm - mat[0][1] - mat[0][2]
	mat[1][1] = sm - mat[1][0] - mat[1][2]
	mat[2][2] = sm - mat[2][0] - mat[2][1]
	for i in mat:
		print(*i)
mat = []
for i in range(3):
	mat.append(int_arr())
solve(mat)


def sudoku():
	(x11, x21, x31) = [int(x) for x in input().split()]
	(x12, x22, x32) = [int(x) for x in input().split()]
	(x13, x23, x33) = [int(x) for x in input().split()]
	for i in range(0, 100001):
		x11 = i
		x22 = x11 + x21 + x31 - (x12 + x32)
		x33 = x11 + x21 + x31 - (x22 + x11)
		if x11 + x22 + x33 == x11 + x21 + x31 == x31 + x32 + x33:
			print(x11, x21, x31)
			print(x12, x22, x32)
			print(x13, x23, x33)
			return
sudoku()


a = []
for i in range(3):
	a.append(list(map(int, input().split())))
r1 = sum(a[0])
r2 = sum(a[1])
r3 = sum(a[2])
a[0][0] = (r3 + r2 - r1) // 2
a[1][1] = a[0][0] + (r1 - r2)
a[2][2] = a[0][0] + (r1 - r3)
for i in range(3):
	print(*a[i])


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
m = [l1, l2, l3]
c1 = m[0][1] + m[0][2]
c2 = m[1][0] + m[1][2]
c3 = m[2][0] + m[2][1]
r2 = (c3 - c2 + c1) / 2
r1 = c3 - r2
r3 = c1 - r2
print(int(r1), m[0][1], m[0][2])
print(m[1][0], int(r2), m[1][2])
print(m[2][0], m[2][1], int(r3))


mat = []
for i in range(3):
	l = list(map(int, input().split()))
	mat.append(l)
y = (mat[0][1] + mat[0][2] + mat[2][0] + mat[2][1] - (mat[1][0] + mat[1][2])) // 2
x = mat[1][0] + mat[1][2] + y - mat[0][1] - mat[0][2]
z = mat[1][0] + mat[1][2] + y - mat[2][0] - mat[2][1]
mat[0][0] = x
mat[1][1] = y
mat[2][2] = z
for i in range(3):
	for j in range(3):
		print(mat[i][j], end=' ')
	print()


import math
import collections

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

def cstr():
	return list(map(str, input().split(' ')))

def solve():
	matrix = []
	for _ in range(3):
		matrix.append(cint())
	for i in range(1, 10 ** 5 + 1):
		col1 = i + matrix[1][0] + matrix[2][0]
		y = col1 - matrix[1][0] - matrix[1][2]
		z = col1 - matrix[2][0] - matrix[2][1]
		if y > 0 and z > 0 and (i + y + z == col1):
			matrix[0][0] = i
			matrix[1][1] = y
			matrix[2][2] = z
			for row in matrix:
				for j in row:
					print(j, end=' ')
				print('')
			return
	return
t = 1
while t != 0:
	solve()
	t -= 1


from sys import stdin, stdout, setrecursionlimit
from gc import disable
gets = input
puts = print
input = stdin.readline
print = stdout.write

def main() -> int:
	disable()
	sq = [list(map(int, input().split())) for i in range(3)]
	sq[1][1] = (sq[0][1] + sq[0][2] + (sq[2][0] + sq[2][1] - (sq[1][0] + sq[1][2]))) // 2
	sq[0][0] = sq[2][0] + sq[2][1] - sq[1][1]
	sq[2][2] = sq[1][0] + sq[1][2] - sq[0][0]
	for i in sq:
		for j in i:
			print('%i ' % j)
		print('\n')
	return 0
main()


l = []
for i in range(3):
	k = list(map(int, input().split()))
	l.append(k)
l[1][1] = (2 * l[0][2] + l[1][2] - l[2][1]) // 2
l[0][0] = l[0][2] + l[1][2] - l[1][1]
l[2][2] = l[0][1] + l[2][1] - l[0][0]
for i in range(3):
	print(*l[i])


z = [[int(j) for j in input().split()] for i in range(3)]
z[0][0] = (sum(z[1]) + sum(z[2]) - sum(z[0])) // 2
z[1][1] = sum(z[2]) - z[0][0]
z[2][2] = z[0][1] + z[0][2] - z[1][1]
for i in z:
	print(*i)


a = []
for i in range(3):
	a += list(map(int, input().split()))
a[0] = (2 * a[7] + a[6] - a[2]) // 2
a[4] = a[7] + a[6] - a[0]
a[8] = a[1] + a[2] - a[4]
print(*a[:3])
print(*a[3:6])
print(*a[6:9])


__author__ = 'Rajan'
x = 0
y = 0
z = 0
(a1, b1, c1) = map(int, input().split())
x = b1 + c1
(a2, b2, c2) = map(int, input().split())
y = a2 + c2
(a3, b3, c3) = map(int, input().split())
z = a3 + b3
sum = (x + y + z) // 2
a1 = sum - x
b2 = sum - y
c3 = sum - z
print(a1, b1, c1)
print(a2, b2, c2)
print(a3, b3, c3)


a = []
for i in range(3):
	nums = input()
	numbers = nums.split()
	a.append(numbers)
for i in range(len(a)):
	for j in range(len(a[i])):
		a[i][j] = int(a[i][j])
a[0][0] = int((a[2][0] + a[2][1] + a[1][0] + a[1][2] - a[0][1] - a[0][2]) / 2)
a[1][1] = int((a[0][1] + a[0][2] + a[2][0] + a[2][1] - a[1][0] - a[1][2]) / 2)
a[2][2] = int((a[0][1] + a[0][2] + a[1][0] + a[1][2] - a[2][0] - a[2][1]) / 2)
for i in range(len(a)):
	print(a[i][0], a[i][1], a[i][2])


y = list(map(int, input().rstrip().split()))
k = list(map(int, input().rstrip().split()))
l = list(map(int, input().rstrip().split()))
k[1] = (2 * l[0] - y[1] + k[0]) // 2
y[0] = l[0] + l[1] - k[1]
l[2] = y[1] + y[2] - k[1]
print(*y)
print(*k)
print(*l)


a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a[0] = (b[0] + b[2] + c[0] + c[1] - a[1] - a[2]) // 2
b[1] = (a[1] + a[2] + c[0] + c[1] - b[0] - b[2]) // 2
c[2] = (a[1] + a[2] + b[0] + b[2] - c[0] - c[1]) // 2
print(*a)
print(*b)
print(*c)


(a, b, c) = map(int, input().split())
(p, q, r) = map(int, input().split())
(x, y, z) = map(int, input().split())
a = (p + r + x + y - b - c) // 2
q = (b + c + x + y - p - r) // 2
z = (b + c + p + r - x - y) // 2
print(a, b, c)
print(p, q, r)
print(x, y, z)


def main():
	from sys import stdin, stdout
	(x, a, b) = list(map(int, stdin.readline().split()))
	(c, y, d) = list(map(int, stdin.readline().split()))
	(e, f, z) = list(map(int, stdin.readline().split()))
	x = (2 * b + d - c) // 2
	z = b + e - x
	y = x + c + e - f - a
	stdout.write(str(x) + ' ' + str(a) + ' ' + str(b) + '\n')
	stdout.write(str(c) + ' ' + str(y) + ' ' + str(d) + '\n')
	stdout.write(str(e) + ' ' + str(f) + ' ' + str(z))

def __starting_point():
	main()
__starting_point()


a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = [a[1] + a[2], b[0] + b[2], c[0] + c[1]]
m = max(d)
a[0] = m - a[1] - a[2] + 1
b[1] = m - b[0] - b[2] + 1
c[2] = m - c[0] - c[1] + 1
while a[2] + c[0] != a[0] + c[2]:
	a[0] += 1
	b[1] += 1
	c[2] += 1
print(a[0], a[1], a[2])
print(b[0], b[1], b[2])
print(c[0], c[1], c[2])


mat = []
for i in range(3):
	row = list(map(int, input().split()))
	mat.append(row)
sm = (sum(mat[0]) + sum(mat[1]) + sum(mat[2])) // 2
mat[0][0] = sm - mat[0][1] - mat[0][2]
mat[1][1] = sm - mat[1][0] - mat[1][2]
mat[2][2] = sm - mat[2][0] - mat[2][1]
for i in range(3):
	print(*mat[i])


l1 = []
for i in range(3):
	a = list(map(int, input().split()))
	l1.append(a)
a = l1[2][0] + (l1[2][1] - l1[0][1]) // 2
b = l1[0][2] + l1[1][2] - a
c = l1[0][2] + (l1[0][1] - l1[2][1]) // 2
(l1[0][0], l1[1][1], l1[2][2]) = (a, b, c)
for i in range(3):
	for j in range(3):
		print(l1[i][j], end=' ')
	print('')


a = list((list(map(int, input().split())) for _ in range(3)))
for x in range(10 ** 5 + 1):
	a[0][0] = x
	a[1][1] = sum(a[0]) - sum(a[1])
	a[2][2] = sum(a[0]) - sum(a[2])
	t = 0
	for i in range(3):
		t += a[i][i]
	s = 0
	check = 0
	for i in range(3):
		s = 0
		for j in range(3):
			s += a[j][i]
		if s == t:
			check += 1
	if t == sum(a[0]) and check == 3:
		for j in range(3):
			print(*a[j])
		exit()
	a[1][1] = 0
	a[2][2] = 0


import sys, threading, os.path
import string
import collections, heapq, math, bisect
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)

def main():
	if os.path.exists('in.txt'):
		input = open('in.txt', 'r')
	else:
		input = sys.stdin
	arr = []
	for i in range(3):
		arr.append(list(map(int, input.readline().split())))
	a = arr[0][1] + arr[0][2]
	b = arr[1][0] + arr[1][2]
	c = arr[2][0] + arr[2][1]
	arr1 = sorted([a, b, c], reverse=True)
	z = max(arr1)
	for i in range(3):
		arr1[i] = z - arr1[i]
	while arr1[0] + arr1[1] + arr1[2] != z + arr1[0]:
		arr1[0] += 1
		arr1[1] += 1
		arr1[2] += 1
	idl = z + arr1[0]
	for x in arr1:
		if x + a == idl:
			arr[0][0] = x
			break
	for x in arr1:
		if x + b == idl:
			arr[1][1] = x
			break
	for x in arr1:
		if x + c == idl:
			arr[2][2] = x
			break
	sol = ''
	for i in range(3):
		sol += ' '.join(map(str, arr[i]))
		if i + 1 < 3:
			sol += '\n'
	output = sol
	if os.path.exists('out.txt'):
		open('out.txt', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
main()


def fillSquare(x, s):
	s[0][0] = x
	a = s[0][0] + s[0][1] + s[0][2]
	b = s[1][0] + s[1][2]
	s[1][1] = a - b
	c = s[2][0] + s[2][1]
	s[2][2] = a - c

def isPossible(x, s):
	fillSquare(x, s)
	a = s[0][0] + s[0][1] + s[0][2]
	b = s[1][0] + s[1][1] + s[1][2]
	c = s[2][0] + s[2][1] + s[2][2]
	d = s[0][0] + s[1][0] + s[2][0]
	e = s[0][1] + s[1][1] + s[2][1]
	f = s[0][2] + s[1][2] + s[2][2]
	g = s[0][0] + s[1][1] + s[2][2]
	h = s[0][2] + s[1][1] + s[2][0]
	if a == b and b == c and (c == d) and (d == e) and (e == f) and (f == g) and (g == h):
		return True
	return False

def findSquare(square):
	for i in range(100000 + 1):
		if isPossible(i, square.copy()):
			fillSquare(i, square)
			return
square = []
for i in range(3):
	s = list(map(int, input().split()))
	square.append(s)
findSquare(square)
for i in square:
	s = ''
	for c in i:
		s += str(c) + ' '
	print(s)


ans = []
fs = 0
ss = 0
ts = 0
for i in range(3):
	l = list(map(int, input().split()))
	if i == 0:
		fs = sum(l)
	elif i == 1:
		ss = sum(l)
	else:
		ts = sum(l)
	ans.append(l)
x = 0
y = 0
z = 0
y = (fs + (ts - ss)) / 2
z = fs - y
x = ts - y
for i in range(3):
	for j in range(3):
		if i == j:
			if i == 0:
				ans[i][j] = int(x)
			elif i == 1:
				ans[i][j] = int(y)
			else:
				ans[i][j] = int(z)
print('\n'.join(['\t'.join([str(cell) for cell in row]) for row in ans]))


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

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

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

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

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

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

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
ml = [lmp() for i in range(3)]
x = sum([sum(i) for i in ml]) // 2
for i in range(3):
	for j in range(3):
		if i == j:
			ml[i][j] = x - sum(ml[i])
for i in ml:
	print(*i)


arr = []
for i in range(3):
	arr.append(list(map(int, input().split())))
s = [sum(i) for i in arr]
arr[0][0] = max(s) - s[0] + 1
arr[1][1] = max(s) - s[1] + 1
arr[2][2] = max(s) - s[2] + 1
d = arr[0][0] + arr[1][1] + arr[2][2]
tr = sum(arr[0])
while tr > d:
	arr[0][0] += 1
	arr[1][1] += 1
	arr[2][2] += 1
	d = arr[0][0] + arr[1][1] + arr[2][2]
	tr = sum(arr[0])
for i in arr:
	print(' '.join([str(j) for j in i]))


arr = [[0] * 3 for _ in range(3)]
su1 = []
for i in range(3):
	(a, b, c) = map(int, input().split())
	arr[i][0] = a
	arr[i][1] = b
	arr[i][2] = c
su = arr[0][1] + arr[0][2] + arr[1][0] + arr[1][2] + arr[2][0] + arr[2][1]
su = int(su / 2)
arr[0][0] = su - (arr[0][1] + arr[0][2])
arr[1][1] = su - (arr[1][0] + arr[1][2])
arr[2][2] = su - (arr[2][0] + arr[2][1])
for i in range(3):
	for j in range(3):
		print(arr[i][j], end=' ')
	print()


l = []
for i in range(3):
	tmp = [] * 3
	tmp = list(map(int, input().split(' ')))
	l.append(tmp[:])
for i in range(1, 100001):
	z = i
	sum = l[0][1] + l[0][2] + z
	x = sum - l[0][1] - l[2][1]
	y = sum - l[2][0] - l[2][1]
	l[0][0] = z
	l[1][1] = x
	l[2][2] = y
	prv = x + y + z
	ok = 1
	tmp = []
	for j in range(3):
		sum1 = 0
		sum2 = 0
		for k in range(3):
			sum1 += l[j][k]
			sum2 += l[k][j]
		if sum1 != sum2 or sum1 != prv:
			ok = 0
			break
		if ok == 0:
			break
	if ok == 1:
		break
for i in range(3):
	for j in range(3):
		print(l[i][j], end=' ')
	print()


def solve(s):
	rows = list(map(sum, [s[i] for i in range(3)]))
	r = sorted(rows)
	d1 = r[1] - r[0]
	d2 = r[2] - r[1]
	m = 3 * (r[0] - d2) / 2 + 2 * d2 + d1
	m = int(m)
	for i in range(3):
		s[i][i] = m - rows[i]
	return s
res = solve([list(map(int, input().split())) for _ in range(3)])
for i in range(3):
	print(' '.join(map(str, res[i])))


import sys
import math as m

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)
ms = []
for i in range(3):
	a = llinp()
	ms.append(a)
tot = (ms[0][1] + ms[0][2] + ms[1][0] + ms[1][2] + ms[2][0] + ms[2][1]) // 2
ms[0][0] = tot - (ms[0][1] + ms[0][2])
ms[1][1] = tot - (ms[1][0] + ms[1][2])
ms[2][2] = tot - (ms[2][0] + ms[2][1])
for i in ms:
	print(*i)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(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 list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 5
T = 1
for _ in range(T):
	a = []
	for i in range(3):
		a.append(list(map(int, stdin.readline().rstrip().split())))
	x = sum(a[0])
	y = sum(a[1])
	z = sum(a[2])
	s = (x + y + z) // 2
	a[0][0] = s - x
	a[1][1] = s - y
	a[2][2] = s - z
	for i in a:
		print(*i)


x = []
s = 0
for i in range(3):
	y = list(map(int, input().split()))
	x.append(y)
	s += sum(y)
s = s // 2
x[0][0] = s - x[0][1] - x[0][2]
x[1][1] = s - x[1][0] - x[1][2]
x[2][2] = s - x[2][0] - x[2][1]
for i in x:
	for j in i:
		print(j, end=' ')
	print('')


(a, b, c) = map(int, input().split())
(d, e, f) = map(int, input().split())
(g, h, i) = map(int, input().split())
for e in range(100001):
	s = e + b + h
	a = s - b - c
	i = s - c - f
	if a > 0 and i > 0 and (e > 0) and (a + e + i == s):
		print(a, b, c)
		print(d, e, f)
		print(g, h, i)
		break


l = []
l = [list(map(int, input().split())) for i in range(3)]
sum1 = sum((sum(x) if isinstance(x, list) else x for x in l))
sum_final = sum1 // 2
l[0][0] = sum_final - (l[0][1] + l[0][2])
l[1][1] = sum_final - (l[1][0] + l[1][2])
l[2][2] = sum_final - (l[2][0] + l[2][1])
for i in range(3):
	print(l[i][0], l[i][1], l[i][2])


a = [None for _ in range(3)]
a[0] = list(map(int, input().split()))
a[1] = list(map(int, input().split()))
a[2] = list(map(int, input().split()))
a[0][0] = (-a[0][2] + a[2][0] + 2 * a[2][1]) // 2
a[1][1] = a[0][0] + a[0][1] + a[0][2] - a[1][0] - a[1][2]
a[2][2] = a[0][0] + a[0][1] + a[0][2] - a[2][0] - a[2][1]
for i in range(3):
	for j in range(3):
		print(a[i][j], end=' ')
	print()


import fileinput

def sommeColonne(t, col):
	res = 0
	for i in range(3):
		res += t[i][col]
	return res

def sommeLigne(t, lig):
	res = 0
	for i in range(3):
		res += t[lig][i]
	return res

def sommeDiag1(t):
	return t[0][0] + t[1][1] + t[2][2]

def sommeDiag2(t):
	return t[0][2] + t[1][1] + t[2][0]

def valide(v):
	return v >= 1 and v <= 100000

def cherche(t):
	for t[0][0] in range(1, 100001):
		s = sommeLigne(t, 0)
		t[1][1] = s - t[1][0] - t[1][2]
		t[2][2] = s - t[2][0] - t[2][1]
		if (valide(t[1][1]) and valide(t[2][2])) and (sommeColonne(t, 0) == s or sommeColonne(t, 1) == s or sommeColonne(t, 2) == s) and (sommeDiag1(t) == s and sommeDiag2(t) == s):
			return 'YES'
	return 'NO'

def saisie():
	t = [[], [], []]
	for i in range(3):
		t[i] = list(map(int, input().rstrip().split(' ')))
	return t

def printSquare(t):
	for lig in range(3):
		print(t[lig][0], t[lig][1], t[lig][2])
t = saisie()
sol = cherche(t)
if sol == 'YES':
	printSquare(t)
else:
	print('pas de solution trouvée')


x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = list(map(int, input().split()))
a = [x, y, z]
m = (a[1][0] + a[1][2]) // 2
a[1][1] = m
s = sum(a[1])
f = s - (a[0][1] + a[0][2])
a[0][0] = f
t = s - (a[2][0] + a[2][1])
a[2][2] = t
for i in a:
	print(*i)


(l, q) = ([0] * 3, 0)
for i in range(3):
	l[i] = list(map(int, input().split()))
	q += sum(l[i])
for i in range(3):
	l[i][i] = q // 2 - sum(l[i])
	print(*l[i])


(a1, a2, a3) = map(int, input().split())
(a4, a5, a6) = map(int, input().split())
(a7, a8, a9) = map(int, input().split())
for i in range(1, 10 ** 5 + 1):
	a1 = i
	s = a1 + a2 + a3
	a5 = s - (a4 + a6)
	a9 = s - (a7 + a8)
	if a1 + a5 + a9 == s and a3 + a5 + a7 == s:
		break
print(a1, a2, a3)
print(a4, a5, a6)
print(a7, a8, a9)


r0 = list(map(int, input().split()))
r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
for i in range(1, 10 ** 5 + 1 + 1):
	r0[0] = i
	r1[1] = sum(r0) - r1[0] - r1[2]
	r2[2] = sum(r0) - r2[0] - r2[1]
	if r1[1] > 0 and r2[2] > 0:
		if sum(r0) == sum(r1) == sum(r2) == r0[0] + r1[0] + r2[0] == r0[1] + r1[1] + r2[1] == r0[2] + r1[2] + r2[2] == r0[0] + r1[1] + r2[2] == r0[2] + r1[1] + r2[0]:
			print(*r0)
			print(*r1)
			print(*r2)
		else:
			r0[0] = 0
			r1[1] = 0
			r2[2] = 0
	else:
		r0[0] = 0
		r1[1] = 0
		r2[2] = 0


(SUM, X) = (0, [])
for i in range(3):
	Temp = list(map(int, input().split()))
	SUM += sum(Temp)
	X.append(Temp)
for i in range(3):
	X[i][i] = SUM // 2 - sum(X[i])
	print(*X[i])


def main():

	def is_valid(grid):
		if sum(grid[0]) != sum(grid[1]) or sum(grid[1]) != sum(grid[2]):
			return False
		if grid[0][0] + grid[1][1] + grid[2][2] != grid[0][2] + grid[1][1] + grid[2][0]:
			return False
		return True
	grid = []
	for i in range(3):
		grid.append(list(map(int, input().split(' '))))
	s = sum(grid[0]) + sum(grid[1]) + sum(grid[2])
	grid[0][0] = s // 2 - sum(grid[0])
	grid[1][1] = s // 2 - sum(grid[1])
	grid[2][2] = s // 2 - sum(grid[2])
	for i in range(3):
		print(' '.join(list(map(str, grid[i]))))
main()


a = []
for _ in range(3):
	a.append(list(map(int, input().split())))

def printMSquare(a):
	sum = 0
	for i in range(3):
		for j in range(3):
			sum += a[i][j]
	sum = sum // 2
	for i in range(3):
		row_sum = 0
		for j in range(3):
			row_sum += a[i][j]
		a[i][i] = sum - row_sum
	for i in range(3):
		for j in range(3):
			print(a[i][j], end=' ')
		print(' ')
printMSquare(a)


s = [[int(i) for i in input().split()] for j in range(3)]
x = 0
while True:
	x += 1
	sumk = x + s[0][1] + s[0][2]
	y = sumk - s[1][0] - s[1][2]
	z = sumk - s[2][0] - s[2][1]
	if x + s[1][0] + s[2][0] == sumk and s[0][1] + y + s[2][1] == sumk and (s[0][2] + s[1][2] + z == sumk) and (x + y + z == sumk) and (s[0][2] + y + s[2][0] == sumk):
		s[0][0] = x
		s[1][1] = y
		s[2][2] = z
		break
for i in range(3):
	print(' '.join([str(j) for j in s[i]]))


A = []
B = []
for i in range(3):
	A.append(list(map(int, input().split())))
for i in range(3):
	c = []
	for j in range(3):
		c.append(A[j][i])
	B.append(c)
for i in range(1, 10 ** 5 + 1):
	Mid = i
	if sum(A[1]) + i == sum(B[1]) + i == A[0][2] + i + A[2][0]:
		sum1 = sum(A[1]) + i
		Last = sum1 - sum(B[2])
		if sum(A[2]) + Last == sum(B[2]) + Last == sum1:
			First = sum1 - sum(B[0])
			if sum(A[0]) + First == sum(B[0]) + First == sum1 and First + Mid + Last == sum1:
				A[0][0] = First
				A[1][1] = Mid
				A[2][2] = Last
				break
for i in A:
	for j in i:
		print(j, end=' ')
	print()


from sys import stdin, stdout
from collections import Counter

def is_magic(l1, l2, l3):
	s1 = sum(l1)
	s2 = sum(l2)
	s3 = sum(l3)
	s4 = l1[0] + l2[0] + l3[0]
	s5 = l1[1] + l2[1] + l3[1]
	s6 = l1[2] + l2[2] + l3[2]
	s7 = l1[0] + l2[1] + l3[2]
	s8 = l1[2] + l2[1] + l3[0]
	return s1 == s2 == s3 == s4 == s5 == s6 == s7 == s8

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

def format_output(lists):
	res = ''
	for alist in lists:
		res += format_output_list(alist)
	return res

def solve(l1, l2, l3):
	for i in range(100001):
		if l1[1] + i + l3[1] == l1[2] + i + l3[0] == l1[2] + i + l3[0]:
			l2[1] = i
			l3[2] = l2[1] + l2[0] - l3[0] - l3[1] + l2[2]
			l1[0] = l1[1] + l3[1] - l3[2]
			if is_magic(l1, l2, l3):
				return format_output([l1, l2, l3])
l1 = list(map(int, stdin.readline().rstrip().split()))
l2 = list(map(int, stdin.readline().rstrip().split()))
l3 = list(map(int, stdin.readline().rstrip().split()))
stdout.write(str(solve(l1, l2, l3)))


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
A = [L() for i in range(3)]
for i in range(1, 10 ** 5 + 1):
	x = i + sum(A[0])
	y = x - A[0][1] - A[2][1]
	if y <= 0:
		continue
	if A[1][0] + A[1][2] + y == x and A[0][2] + A[2][0] + y == x:
		z = x - i - y
		if z > 0 and A[0][2] + A[1][2] + z == x and (A[2][0] + A[2][1] + z == x):
			A[0][0] = i
			A[1][1] = y
			A[2][2] = z
			for i in range(3):
				print(*A[i])
			exit()
endtime = time.time()


def readln(t):
	_ = input().split(' ')
	return [t(_[__]) for __ in range(0, len(_))]
(a, e, f) = readln(int)
(g, b, h) = readln(int)
(i, j, c) = readln(int)
a = i + j / 2 - e / 2
b = j / 2 + e / 2
c = e / 2 + f - j / 2
print(round(a), e, f)
print(g, round(b), h)
print(i, j, round(c))


ans = [[int(i) for i in input().split()] for _ in range(3)]
s = sum([sum(i) for i in ans]) // 2
for i in range(3):
	ans[i][i] = s - sum(ans[i])
print('\n'.join([' '.join(['{}'.format(i) for i in row]) for row in ans]))


n = 3
m = []
for i in range(n):
	l = list(map(int, input().split()))
	m.append(l)
a1 = m[0][1] + m[0][2]
a2 = m[1][0] + m[1][2]
a3 = m[2][0] + m[2][1]
k = (a1 + a2 + a3) // 2
a11 = k - a1
a22 = k - a2
a33 = k - a3
print(a11, m[0][1], m[0][2])
print(m[1][0], a22, m[1][2])
print(m[2][0], m[2][1], a33)


li1 = list(map(int, input().split(' ')))
li2 = list(map(int, input().split(' ')))
li3 = list(map(int, input().split(' ')))
li1[0] = (sum(li3) - sum(li1) + li3[0] + li1[2]) // 2
li3[2] = li3[0] + li1[2] - li1[0]
li2[1] = sum(li1) - sum(li2)
for i in range(3):
	print(li1[i], end=' ')
print()
for i in range(3):
	print(li2[i], end=' ')
print()
for i in range(3):
	print(li3[i], end=' ')
print()


_1 = input().split(' ')
_2 = input().split(' ')
_3 = input().split(' ')
a = int(_1[1])
b = int(_1[2])
c = int(_2[0])
d = int(_2[2])
e = int(_3[0])
f = int(_3[1])
s = a + b + c + d + e + f
s = s // 2
_1[0] = s - a - b
_2[1] = s - c - d
_3[2] = s - e - f
print(_1[0], _1[1], _1[2])
print(_2[0], _2[1], _2[2])
print(_3[0], _3[1], _3[2])


ans = [[int(i) for i in input().split()] for _ in range(3)]
mx = max([sum(i) for i in ans]) + 1
while sum([mx - sum(i) for i in ans]) != mx:
	mx += 1
for i in range(3):
	ans[i][i] = mx - sum(ans[i])
print('\n'.join([' '.join(['{}'.format(i) for i in row]) for row in ans]))


r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))
suma = int((r1[1] + r1[2] + r2[0] + r2[2] + r3[0] + r3[1]) / 2)
r1[0] = suma - r1[1] - r1[2]
r2[1] = suma - r2[0] - r2[2]
r3[2] = suma - r3[0] - r3[1]
print(*r1)
print(*r2)
print(*r3)


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()]
a = array()
b = array()
c = array()
x = (sum(b) + sum(c) - sum(a)) // 2
y = (sum(a) + sum(c) - sum(b)) // 2
z = (sum(a) + sum(b) - sum(c)) // 2
(a[0], b[1], c[2]) = (x, y, z)
print(*a)
print(*b)
print(*c)


(a11, a12, a13) = map(int, input().split())
(a21, a22, a23) = map(int, input().split())
(a31, a32, a33) = map(int, input().split())
a11 = (a21 + a23 + a31 + a32 - a12 - a13) // 2
a22 = a12 + a13 + a11 - a21 - a23
a33 = a12 + a13 + a11 - a31 - a32
print(a11, a12, a13)
print(a21, a22, a23)
print(a31, a32, a33)


l = []
for i in range(3):
	l.append(list(map(int, input().split())))
l[0][0] = (l[1][2] + l[2][1]) // 2
l[1][1] = (l[0][2] + l[2][0]) // 2
l[2][2] = (l[1][0] + l[0][1]) // 2
for i in range(3):
	print(end='\n')
	for r in l[i]:
		print(r, end=' ')


l = list(map(int, input().split()))
k = list(map(int, input().split()))
n = list(map(int, input().split()))
i = max(sum(l), sum(k), sum(n)) + 1
while True:
	a = i - sum(l)
	b = i - sum(k)
	c = i - sum(n)
	if a + b + c == sum(l) + a == sum(k) + b == sum(n) + c == a + k[0] + n[0] == b + l[1] + n[1] == l[2] + k[2] + c == l[2] + b + n[0]:
		print(a, l[1], l[2])
		print(k[0], b, k[2])
		print(n[0], n[1], c)
		break
	else:
		i += 1


arr = []
for i in range(3):
	row = input()
	arr.append(list(map(int, row.split())))
arr_sum = int((arr[0][1] + arr[0][2] + arr[1][0] + arr[1][2] + arr[2][0] + arr[2][1]) / 2)
print(arr_sum - arr[0][1] - arr[0][2], arr[0][1], arr[0][2])
print(arr[1][0], arr_sum - arr[1][0] - arr[1][2], arr[1][2])
print(arr[2][0], arr[2][1], arr_sum - arr[2][0] - arr[2][1])


a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
sa = sum(a)
sb = sum(b)
sc = sum(c)
s = (sa + sb + sc) // 2
a[0] = s - sa
b[1] = s - sb
c[2] = s - sc
print(*a)
print(*b)
print(*c)


import sys
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
sys.setrecursionlimit(10 ** 7)
mod = 1000000007

def main():
	(a, b, c) = map(int, sys.stdin.readline().split())
	(p, q, r) = map(int, sys.stdin.readline().split())
	(x, y, z) = map(int, sys.stdin.readline().split())
	tot = (b + c + p + r + x + y) // 2
	a = tot - (b + c)
	q = tot - (p + r)
	z = tot - (x + y)
	print(a, b, c)
	print(p, q, r)
	print(x, y, z)
main()


(x, a1, b1) = map(int, input().strip().split(' '))
(a2, y, b2) = map(int, input().strip().split(' '))
(a3, b3, z) = map(int, input().strip().split(' '))
x1 = a1 + b1
y1 = a2 + b2
z1 = a3 + b3
x = (y1 + z1 - x1) // 2
y = (x1 + z1 - y1) // 2
z = (x1 + y1 - z1) // 2
print(x, a1, b1, end=' ')
print()
print(a2, y, b2, end=' ')
print()
print(a3, b3, z, end=' ')


def get_ans():
	(x, b, c) = map(int, input().split())
	(d, y, f) = map(int, input().split())
	(g, h, z) = map(int, input().split())
	s = (b + c + d + f + g + h) // 2
	x = s - (b + c)
	y = s - (d + f)
	z = s - (g + h)
	print(x, b, c)
	print(d, y, f)
	print(g, h, z)
get_ans()


l = list(map(int, input().split()))
d = list(map(int, input().split()))
w = list(map(int, input().split()))
(x, y, z) = (sum(l), sum(d), sum(w))
l[0] = (z + y - x) // 2
d[1] = (z + x - y) // 2
w[2] = (x + y - z) // 2
print(*l)
print(*d)
print(*w)


A = []
for _ in range(3):
	A.append([int(x) for x in input().split(' ')])
x = (sum(A[2]) + sum(A[1]) - sum(A[0])) / 2
y = (sum(A[2]) + sum(A[0]) - sum(A[1])) / 2
z = (sum(A[0]) + sum(A[1]) - sum(A[2])) / 2
A[0][0] = int(x)
A[1][1] = int(y)
A[2][2] = int(z)
for j in range(3):
	print(' '.join((str(v) for v in A[j])))


n = 3
m = 3
a = [[0] * n for _ in range(m)]
for i in range(n):
	a[i] = [int(j) for j in input().strip().split(' ')]
a[0][0] = (a[1][2] + a[2][1]) // 2
a[1][1] = (a[1][2] + a[1][0]) // 2
a[2][2] = (a[0][1] + a[1][0]) // 2
for i in a:
	print(*i)


def main():
	square = [list(map(int, input().split())) for _ in range(3)]
	for x in range(1, 100001):
		s = square[0][1] + square[0][2] + x
		y = s - square[1][0] - square[1][2]
		z = s - square[2][0] - square[2][1]
		if s > 0 and y > 0 and (z > 0):
			cond1 = x + square[1][0] + square[2][0] == s
			cond2 = y + square[0][1] + square[2][1] == s
			cond3 = z + square[0][2] + square[1][2] == s
			cond4 = y + square[2][0] + square[0][2] == s
			cond5 = x + y + z == s
			if cond1 and cond2 and cond3 and cond4 and cond5:
				square[0][0] = x
				square[1][1] = y
				square[2][2] = z
				for row in square:
					print(*row)
				return
main()


grid = []
for x in range(3):
	j = input().split()
	grid.append([int(i) for i in j])
s = [sum(i) for i in grid]
grid[0][0] = max(s) - s[0] + 1
grid[1][1] = max(s) - s[1] + 1
grid[2][2] = max(s) - s[2] + 1
diag = grid[0][0] + grid[1][1] + grid[2][2]
tr = sum(grid[0])
while tr > diag:
	grid[0][0] += 1
	grid[1][1] += 1
	grid[2][2] += 1
	diag = grid[0][0] + grid[1][1] + grid[2][2]
	tr = sum(grid[0])
for i in grid:
	print(' '.join([str(x) for x in i]))


def MS(arr1, arr2, arr3):
	suma = 0
	for i in range(3):
		suma += arr1[i] + arr2[i] + arr3[i]
	suma = suma // 2
	arr1[0] = suma - arr1[1] - arr1[2]
	arr2[1] = suma - arr2[0] - arr2[2]
	arr3[2] = suma - arr3[0] - arr3[1]
	arr_aux = ' '.join(map(str, arr1))
	print(arr_aux)
	arr_aux = ' '.join(map(str, arr2))
	print(arr_aux)
	arr_aux = ' '.join(map(str, arr3))
	print(arr_aux)
	return
arr1 = list(map(int, input().strip().split()))
arr2 = list(map(int, input().strip().split()))
arr3 = list(map(int, input().strip().split()))
MS(arr1, arr2, arr3)


l = []
l.append(list(map(int, input().split())))
l.append(list(map(int, input().split())))
l.append(list(map(int, input().split())))
r1 = l[0][1] + l[0][2]
r2 = l[1][0] + l[1][2]
r3 = l[2][0] + l[2][1]
s = (r1 + r2 + r3) // 2
x = s - r1
y = s - r2
z = s - r3
l[0][0] = x
l[1][1] = y
l[2][2] = z
for i in l:
	for j in i:
		print(j, end=' ')
	print()


table = []
for i in range(3):
	arr = list(map(int, input().split()))
	table.append(arr)
s = sum(map(sum, table)) // 2
for i in range(3):
	table[i][i] = s - sum(table[i])
	print(*table[i])


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 = []
	for i in range(3):
		r.append(lis())
	for i in range(1, 100001):
		col = r[0][1] + i + r[2][1]
		re = col - r[1][0] - r[2][0]
		re1 = col - r[0][2] - r[1][2]
		if re + r[0][1] + r[0][2] == col and re1 + r[2][1] + r[2][0] == col and re and re1 and (re + re1 + i == col):
			r[0][0] = re
			r[1][1] = i
			r[2][2] = re1
			break
	for i in r:
		print(*i)


l1 = []
for i in range(0, 3):
	l2 = [int(x) for x in input().split()]
	l1.append(l2)
x = (l1[0][2] + l1[2][0] + l1[1][2] - l1[0][1]) // 2
z = x + l1[0][1] - l1[1][2]
y = x + l1[0][1] - l1[2][0]
l1[0][0] = x
l1[1][1] = y
l1[2][2] = z
for i in range(0, 3):
	for j in range(0, 3):
		print(l1[i][j], end=' ')
	print()


while True:
	try:

		def soln(mx):
			s = sum(map(sum, mx))
			s = s // 2
			for i in range(3):
				mx[i][i] = s - sum(mx[i])
				print(*mx[i])

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


l = []
s = 0
for i in range(3):
	l.append(list(map(int, input().split())))
	s += sum(l[i])
s //= 2
print(s - l[0][1] - l[0][2], l[0][1], l[0][2])
print(l[1][0], s - l[1][0] - l[1][2], l[1][2])
print(l[2][0], l[2][1], s - l[2][0] - l[2][1])


a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
s1 = a[0] + b[0] + c[0]
s2 = a[1] + b[1] + c[1]
s3 = a[2] + b[2] + c[2]
s4 = sum(a)
s5 = sum(b)
s6 = sum(c)
y = int((s4 + s6 - s5) / 2)
x = s6 - int((s4 + s6 - s5) / 2)
z = s4 - int((s4 + s6 - s5) / 2)
a[0] = x
b[1] = y
c[2] = z
print(*a)
print(*b)
print(*c)


a = [list(map(int, input().split())) for i in range(3)]
for y in range(10 ** 5 + 1):
	a[1][1] = y
	s = a[1][0] + a[1][1] + a[1][2]
	a[0][0] = s - a[0][1] - a[0][2]
	a[2][2] = s - a[2][0] - a[2][1]
	fail = False
	for i in range(3):
		fail |= a[i][0] + a[i][1] + a[i][2] != s or a[0][i] + a[1][i] + a[2][i] != s
	fail |= a[0][0] + a[1][1] + a[2][2] != s or a[0][2] + a[1][1] + a[2][0] != s
	if not fail:
		for i in range(3):
			print(*a[i])
		break


def check_magic(tiles):
	if tiles[0][0] + tiles[0][1] + tiles[0][2] == tiles[1][0] + tiles[1][1] + tiles[1][2] == tiles[2][0] + tiles[2][1] + tiles[2][2] == tiles[0][0] + tiles[1][0] + tiles[2][0] == tiles[0][1] + tiles[1][1] + tiles[2][1] == tiles[0][2] + tiles[1][2] + tiles[2][2] == tiles[0][0] + tiles[1][1] + tiles[2][2] == tiles[0][2] + tiles[1][1] + tiles[2][0]:
		return 0

def magic_square(tiles):
	sum_levels = []
	for x in tiles:
		sum_levels.append(sum(x))
	biggest = max(sum_levels)
	for x in range(100001):
		tiles[0][0] = biggest - sum_levels[0] + x
		tiles[1][1] = biggest - sum_levels[1] + x
		tiles[2][2] = biggest - sum_levels[2] + x
		if check_magic(tiles) == 0:
			break
	return tiles
tiles = []
for x in range(3):
	tiles.append(list(map(int, input().split())))
tiles = magic_square(tiles)
for x in tiles:
	for y in x:
		print(y, end=' ')
	print('\n', end='')


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)
mat = []
for i in range(3):
	arr = int_arr()
	mat.append(arr)
(frst, scnd, third) = (sum(mat[0]), sum(mat[1]), sum(mat[2]))
res = (frst + scnd + third) // 2
(mat[0][0], mat[1][1], mat[2][2]) = (res - frst, res - scnd, res - third)
for i in range(3):
	print(*mat[i])


d = []
s = 0
for i in range(3):
	d.append(list(map(int, input().split())))
	s += sum(d[i])
for i in range(3):
	d[i][i] = s // 2 - sum(d[i])
for i in range(3):
	[print(j, end=' ') for j in d[i]]
	print()


def main():
	square = []
	r = []
	for i in range(3):
		temp = list(map(int, input().split()))
		square.append(temp)
		r.append(sum(temp))
	square[0][0] = (r[2] - r[0] + r[1]) // 2
	square[1][1] = (r[0] - r[1] + r[2]) // 2
	square[2][2] = (r[1] - r[2] + r[0]) // 2
	for i in range(3):
		print(*square[i])
main()


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
(a1, b1, c1) = isp()
(a2, b2, c2) = isp()
(a3, b3, c3) = isp()
for i in range(1, 100005):
	x = i + b1 + c1
	a = [[i, b1, c1], [a2, x - a2 - c2, c2], [a3, b3, x - a3 - b3]]
	if check(a):
		for l in range(3):
			print(' '.join(list(map(str, a[l]))))
		quit()


r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))
r = sum(r1) + sum(r2) + sum(r3)
r1[0] = r // 2 - sum(r1)
r2[1] = r // 2 - sum(r2)
r3[2] = r // 2 - sum(r3)
print(*r1)
print(*r2)
print(*r3)


def check_val(mat, row1_num):
	row1_sum = sum(mat[0]) + row1_num
	row2_num = row1_sum - sum(mat[1])
	row3_num = row1_sum - sum(mat[2])
	if row1_num + row2_num + row3_num != row1_sum or mat[0][2] + row2_num + mat[2][0] != row1_sum or row1_num + mat[1][0] + mat[2][0] != row1_sum or (mat[0][1] + row2_num + mat[2][1] != row1_sum) or (mat[2][0] + mat[2][1] + row3_num != row1_sum):
		return False
	return True
mat = []
for _ in range(3):
	mat.append([int(i) for i in input().split()])
for num in range(1, 100001):
	if check_val(mat, num):
		mat[0][0] = num
		row1_sum = sum(mat[0])
		mat[1][1] = row1_sum - sum(mat[1])
		mat[2][2] = row1_sum - sum(mat[2])
for i in range(3):
	print(*mat[i])


h = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
y = sum(h) + sum(b) + sum(c)
y /= 2
y = int(y)
h[0] = y - (h[1] + h[2])
b[1] = y - (b[0] + b[2])
c[2] = y - (c[0] + c[1])
print(h[0], h[1], h[2])
print(b[0], b[1], b[2])
print(c[0], c[1], c[2])


(a, b, c) = map(int, input().split())
(d, e, f) = map(int, input().split())
(g, h, i) = map(int, input().split())
sum1 = a + b + c
sum2 = d + e + f
sum3 = g + h + i
a = (sum1 + sum2 + sum3) // 2 - sum1
e = (sum1 + sum2 + sum3) // 2 - sum2
i = (sum1 + sum2 + sum3) // 2 - sum3
print(a, b, c)
print(d, e, f)
print(g, h, i)


g = []
g.append([int(x) for x in input().split()])
g.append([int(x) for x in input().split()])
g.append([int(x) for x in input().split()])
g[0][0] = (g[1][0] + g[1][2] + g[2][0] + g[2][1] - g[0][1] - g[0][2]) // 2
g[1][1] = (g[0][1] + g[0][2] + g[2][0] + g[2][1] - g[1][0] - g[1][2]) // 2
g[2][2] = (g[1][0] + g[1][2] + g[0][1] + g[0][2] - g[2][0] - g[2][1]) // 2
for i in g:
	for j in i:
		print(j, end=' ')
	print('')


a = []
for i in range(3):
	x = list(map(int, input().strip().split()))
	a.append(x)
x = (a[0][1] + a[0][2] + a[1][0] + a[1][2] + a[2][1] + a[2][0]) // 2
a[0][0] = x - (a[0][1] + a[0][2])
a[1][1] = x - (a[1][0] + a[1][2])
a[2][2] = x - (a[2][1] + a[2][0])
for i in range(3):
	for j in range(3):
		print(a[i][j], end=' ')
	print()


rows = [list(map(int, input().split())) for x in range(3)]
(a, b, c, d) = (rows[0][2], rows[1][2], rows[1][0], rows[2][0])
sums = [c + d, a + d, a + b]
s = sum(sums) // 2
for x in range(3):
	rows[x][x] = s - sums[x]
for x in rows:
	print(' '.join(map(str, x)))


exec('a=[' + 3 * '[*map(int,input().split())],' + ']')
for x in range(1, int(100000.0 + 1)):
	a[0][0] = x
	a[1][1] = sum(a[0]) - sum(a[1])
	a[2][2] = sum(a[0]) - sum(a[2])
	if all((x > 0 and x < 100000.0 + 1 for i in range(3) for x in a[i])) and all((sum(x) == sum(a[0]) for x in [*zip(*a)])) and (sum((a[i][i] for i in range(3))) == sum(a[0])) and (sum((a[i][2 - i] for i in range(3))) == sum(a[0])):
		break
	else:
		a[1][1] = a[2][2] = 0
print(*a[0])
print(*a[1])
print(*a[2])


def main():
	a = [list(map(int, input().split())) for _ in range(3)]
	y = (a[0][2] + a[2][0]) // 2
	x = a[2][1] - a[0][2] + y
	z = a[0][1] + a[0][2] - y
	a[0][0] = x
	a[1][1] = y
	a[2][2] = z
	for row in a:
		print(*row)
main()


p = []
for i in range(0, 3):
	p.append(list(map(int, input().split())))
p[0][0] = (p[0][2] + p[1][2] + p[0][1] + p[2][1] - p[1][0] - p[2][0]) // 2
x = p[0][0] + p[2][0] - p[1][2]
p[1][1] = x
x = p[0][0] + p[1][0] - p[2][1]
p[2][2] = x
for i in range(0, 3):
	s = ''
	for j in range(0, 3):
		s = s + str(p[i][j]) + ' '
	print(s[:-1])


l = []
for x in range(3):
	j = list(map(int, input().split()))
	l.append(j)
s = []
sum = 0
for x in range(3):
	k = 0
	for y in range(3):
		k += l[x][y]
		sum += l[x][y]
	s.append(k)
sum /= 2
for x in range(3):
	l[x][x] = int(sum - s[x])
for x in range(3):
	for y in range(3):
		print(l[x][y], end=' ')
	print()


def zip_sorted(a, b):
	(a, b) = zip(*sorted(zip(a, b)))
	sorted(zip(a, b), key=lambda x: x[1])
	return (a, b)
a = [int(n1) for n1 in input().split()]
b = [int(n1) for n1 in input().split()]
c = [int(n1) for n1 in input().split()]
count = 0
for i in range(1, 10 ** 5 + 1):
	a[0] = i
	b[1] = sum(a) - sum(b)
	if b[1] > 0:
		if sum(a) == sum(b):
			c[2] = sum(a) - (b[1] + a[0])
			if c[2] > 0:
				if sum(c) == sum(a) == sum(b) == c[0] + b[0] + a[0] == c[1] + b[1] + a[1] == c[1] + b[1] + a[1]:
					count = 1
					break
				else:
					a[0] = 0
					b[1] = 0
					c[2] = 0
			else:
				a[0] = 0
				b[1] = 0
				c[2] = 0
		else:
			a[0] = 0
			b[1] = 0
			c[2] = 0
	else:
		a[0] = 0
		b[1] = 0
		c[2] = 0
print(*a)
print(*b)
print(*c)


firstRow = list(map(int, input().split()))
secondRow = list(map(int, input().split()))
thirdRow = list(map(int, input().split()))
y = 1
while True:
	summ = secondRow[0] + secondRow[2] + y
	x = summ - (firstRow[1] + firstRow[2])
	z = summ - (thirdRow[0] + thirdRow[1])
	secondRow[1] = y
	firstRow[0] = x
	thirdRow[2] = z
	if sum(firstRow) == sum(secondRow) == sum(thirdRow) == sum([firstRow[0], secondRow[1], thirdRow[2]]) == sum([firstRow[2], secondRow[1], thirdRow[0]]):
		print(firstRow[0], firstRow[1], firstRow[2])
		print(secondRow[0], secondRow[1], secondRow[2])
		print(thirdRow[0], thirdRow[1], thirdRow[2])
		break
	else:
		y += 1


A = [list(map(int, input().split())) for _ in range(3)]
s = sum(map(sum, A)) // 2
for i in range(3):
	A[i][i] = s - sum(A[i])
	print(*A[i])


from sys import stdin
sq = []
for _ in range(3):
	sq.append(list(map(int, stdin.readline().split())))
new = sq.copy()
for i in range(1, 10 ** 5 + 1):
	firstcol = i + sq[0][1] + sq[0][2]
	j = firstcol - sq[1][0] - sq[1][2]
	k = firstcol - sq[2][0] - sq[2][1]
	if 0 < j <= 10 ** 5 and 0 < k <= 10 ** 5 and (i + j + k == firstcol) and (sum(sq[0] + [i]) == firstcol) and (sum(sq[1] + [j]) == firstcol) and (sum(sq[2] + [k]) == firstcol):
		new[0][0] = i
		new[1][1] = j
		new[2][2] = k
		break
for row in new:
	print(*row)


x = []
for i in range(3):
	x += [list(map(int, input().split()))]
b = (x[0][2] + x[0][2] + x[1][2] - x[2][1]) // 2
c = (x[0][1] - x[1][2] + x[0][1] + x[2][1]) // 2
a = x[1][2] + c - x[0][1]
x[0][0] = a
x[1][1] = b
x[2][2] = c
print(*x[0])
print(*x[1])
print(*x[2])


l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
k = 0
a = sum(l)
b = sum(l1)
c = sum(l2)
p = a + b + c
p = p // 2
l[0] = p - a
l1[1] = p - b
l2[2] = p - c
print(*l)
print(*l1)
print(*l2)


l1 = []
for i in range(0, 3):
	l2 = list(map(int, input().split()))
	l1.append(l2)
l3 = []
for i in range(0, 3):
	l3.append(l1[i][0] + l1[i][1] + l1[i][2])
for i in range(0, 3):
	l3.append(l1[0][i] + l1[1][i] + l1[2][i])
l3.append(l1[0][2] + l1[1][1] + l1[2][0])
c = max(l3)
j = 1
while l1[0][2] + l1[1][1] + l1[2][0] != l1[0][0] + l1[1][1] + l1[2][2]:
	l1[0][0] = c - l1[0][1] - l1[0][2] + j
	l1[1][1] = c - l1[1][0] - l1[1][2] + j
	l1[2][2] = c - l1[2][1] - l1[2][0] + j
	j = j + 1
for x in l1:
	for y in x:
		print(y, end=' ')
	print()


s1 = input()
temp = s1.split()
r1 = [int(i) for i in temp]
s2 = input()
temp = s2.split()
r2 = [int(i) for i in temp]
s3 = input()
temp = s3.split()
r3 = [int(i) for i in temp]
sum = (r1[1] + r1[2] + r2[0] + r2[2] + r3[0] + r3[1]) / 2
r1[0] = int(sum - (r1[1] + r1[2]))
r2[1] = int(sum - (r2[0] + r2[2]))
r3[2] = int(sum - (r3[0] + r3[1]))
for i in r1:
	print(i, end=' ')
print()
for i in r2:
	print(i, end=' ')
print()
for i in r3:
	print(i, end=' ')


a = []
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
s3 = list(map(int, input().split()))
p = (sum(s1) + sum(s2) + sum(s3)) // 2
x1 = p - sum(s1)
x2 = p - sum(s2)
x3 = p - sum(s3)
for i in range(3):
	if s1[i] == 0:
		print(x1, end=' ')
	else:
		print(s1[i], end=' ')
print()
for i in range(3):
	if s2[i] == 0:
		print(x2, end=' ')
	else:
		print(s2[i], end=' ')
print()
for i in range(3):
	if s3[i] == 0:
		print(x3, end=' ')
	else:
		print(s3[i], end=' ')
print()


mat = []
suml = 0
for i in range(3):
	mat.append([int(x) for x in input().split()])
	suml += sum(mat[i])
suml //= 2
mat[0][0] = suml - mat[0][1] - mat[0][2]
mat[1][1] = suml - mat[1][0] - mat[1][2]
mat[2][2] = suml - mat[2][0] - mat[2][1]
for i in range(3):
	print(mat[i][0], mat[i][1], mat[i][2])


arr = []
for _ in range(3):
	arr.append(list(map(int, input().split())))
a = sum(arr[2]) - sum(arr[0])
b = arr[0][2] + arr[2][0]
arr[2][2] = (b - a) // 2
arr[0][0] = (b + a) // 2
arr[1][1] = arr[0][1] + arr[0][2] - arr[2][2]
for i in range(3):
	print(*arr[i])


(x, a, b) = [int(x) for x in input().split()]
(c, y, d) = [int(x) for x in input().split()]
(e, f, z) = [int(x) for x in input().split()]
suml = (a + b + c + d + e + f) // 2
x = suml - a - b
y = suml - c - d
z = suml - e - f
print(x, a, b)
print(c, y, d)
print(e, f, z)


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	(a, b, c) = lst()
	(a1, b1, c1) = lst()
	(a2, b2, c2) = lst()
	rs = (c + a2 + b + c + a2 + b2) // 2
	a = rs - (b + c)
	b1 = rs - (a1 + c1)
	c2 = rs - (b2 + a2)
	print(a, b, c)
	print(a1, b1, c1)
	print(a2, b2, c2)


a = []
for i in range(3):
	a.append(list(map(int, input().split())))
(m, n, o) = (a[0][1] + a[0][2], a[1][0] + a[1][2], a[2][0] + a[2][1])
s = max(m, n, o)
(x, y, z) = (s - m, s - n, s - o)
if x == 0:
	r = 0
elif y == 0:
	r = 1
if z == 0:
	r = 2
m = int((s - x - y - z) / 2)
if r == 0:
	(a[0][0], a[1][1], a[2][2]) = (m, m + y, m + z)
if r == 1:
	(a[0][0], a[1][1], a[2][2]) = (m + x, m, m + z)
if r == 2:
	(a[0][0], a[1][1], a[2][2]) = (m + x, m + y, m)
for i in range(3):
	for j in range(3):
		print(a[i][j], end=' ')
	print('')


q = list(map(int, input().split()))
w = list(map(int, input().split()))
e = list(map(int, input().split()))
suma = (q[1] + q[2] + w[0] + w[2] + e[0] + e[1]) // 2
q[0] = suma - q[1] - q[2]
w[1] = suma - w[0] - w[2]
e[2] = suma - e[0] - e[1]
for i in range(3):
	print(q[i], end=' ')
print()
for i in range(3):
	print(w[i], end=' ')
print()
for i in range(3):
	print(e[i], end=' ')
print()


M = []
for i in range(3):
	L = list(map(int, input().split()))
	M.append(L)
x2 = M[0][2]
x3 = M[1][0]
x5 = M[2][0]
x6 = M[2][1]
M[0][0] = (x2 + x5 + x6 - x3) // 2
M[1][1] = (x2 + x5) // 2
M[2][2] = (x2 + x5 + x3 - x6) // 2
for i in range(3):
	for j in range(3):
		print(M[i][j], end=' ')
	print('')


g = []
o_s = 0
f_s = 0
p_s = 0
t_s = 0
for i in range(3):
	l = list(map(int, input().split()))
	s = sum(l)
	if i == 0:
		p_s = s
		f_s = s
	else:
		t_s += o_s + p_s - s
		o_s += p_s - s
		p_s = s
	g.append(l)
c_s = f_s + (f_s - t_s) // 2
for l_i in g:
	s = sum(l_i)
	a = list()
	for n in l_i:
		if n == 0:
			a.append(c_s - s)
		else:
			a.append(n)
	print(' '.join((str(x) for x in a)))


a = []
a += [[int(x) for x in input().split()]]
a += [[int(x) for x in input().split()]]
a += [[int(x) for x in input().split()]]
d = a[2][1] + a[2][0] - (a[2][1] + a[2][0] - a[0][1] - a[0][2]) - (a[2][1] + a[2][0] - a[1][0] - a[1][2])
z = d // 2
x = z + a[2][1] + a[2][0] - a[0][1] - a[0][2]
y = z + a[2][1] + a[2][0] - a[1][0] - a[1][2]
a[0][0] = x
a[1][1] = y
a[2][2] = z
for i in a:
	print(*i)


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
(s1, s2, s3) = (sum(l1), sum(l2), sum(l3))
b = (s1 + s3 - s2) // 2
a = s3 - b
c = s1 - b
l1[0] = a
l2[1] = b
l3[-1] = c
print(*l1)
print(*l2)
print(*l3)


(a, b, c) = (list(map(int, input().split())), list(map(int, input().split())), list(map(int, input().split())))
(x, y, z, u) = (a[1] + a[2], b[0] + b[2], c[0] + c[1], a[2] + c[0])
t = (u + x + z) // 2
(a[0], b[1], c[2]) = (t - x, t - y, t - z)
print(' '.join((str(i) for i in a)))
print(' '.join((str(i) for i in b)))
print(' '.join((str(i) for i in c)))


l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
s = (sum(l) + sum(l1) + sum(l2)) // 2
l[0] = s - sum(l)
l1[1] = s - sum(l1)
l2[2] = s - sum(l2)
for i in l:
	print(i, end=' ')
print()
for i in l1:
	print(i, end=' ')
print()
for i in l2:
	print(i, end=' ')


import sys
import math
d = []
for i in range(3):
	d.append([int(x) for x in sys.stdin.readline().split()])
a1 = sum(d[0]) - sum(d[1])
a2 = sum(d[1]) - sum(d[2])
for i in range(100000, 0, -1):
	d[0][0] = i
	d[1][1] = d[0][0] + a1
	d[2][2] = d[1][1] + a2
	if d[0][0] + d[1][1] + d[2][2] == sum(d[0]):
		break
for i in range(3):
	print(' '.join([str(x) for x in d[i]]))


import sys
f = sys.stdin
a = [list(map(int, i.split())) for i in f.read().strip().split('\n')]

def solve():
	s = a[0][2] + a[2][0]
	for i in range(1, s):
		a[0][0] = i
		a[2][2] = s - i
		if sum(a[0]) == sum(a[2]):
			break
	a[1][1] = sum(a[0]) - sum(a[1])
	for i in a:
		print(*i)
solve()


ls = []
for i in range(3):
	s = input()
	ls.append(s.split())
for i in range(3):
	for j in range(3):
		ls[i][j] = int(ls[i][j])
for i in range(1, 10 ** 5 + 1):
	ls[0][0] = i
	ls[1][1] = sum(ls[0]) - ls[1][0] - ls[1][2]
	ls[2][2] = sum(ls[0]) - ls[2][0] - ls[2][1]
	if sum(ls[0]) == sum(ls[1]) == sum(ls[2]) == ls[0][0] + ls[1][1] + ls[2][2] == ls[0][2] + ls[1][1] + ls[2][0]:
		break
for i in range(3):
	print(*ls[i])


arr = [[int(x) for x in input().split()] for i in range(3)]
s = sum((sum(x) for x in arr)) // 2
arr[0][0] = s - sum(arr[0])
arr[1][1] = s - sum(arr[1])
arr[2][2] = s - sum(arr[2])
print('\n'.join((' '.join([str(x) for x in l]) for l in arr)))


def box(line, line2, line3):
	suma = (line[1] + line[2] + line2[0] + line2[2] + line3[0] + line3[1]) / 2
	line[0] = int(suma - line[1] - line[2])
	line2[1] = int(suma - line2[0] - line2[2])
	line3[2] = int(suma - line3[0] - line3[1])
	ans = ' '.join(map(str, line)) + '\n' + ' '.join(map(str, line2)) + '\n' + ' '.join(map(str, line3))
	return ans
line1 = list(map(int, input().split()))
line2 = list(map(int, input().split()))
line3 = list(map(int, input().split()))
print(box(line1, line2, line3))


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())
A = []
for _ in range(3):
	A.append(rlinput())
rows = []
for a in A:
	rows.append(sum(a))
for x in range(10 ** 5 + 1):
	sum = rows[0] + x
	y = sum - rows[1]
	z = sum - rows[2]
	if y >= 0 and z >= 0 and (x + y + z == sum):
		A[0][0] = x
		A[1][1] = y
		A[2][2] = z
		break
for a in A:
	print(*a)


l = []
for i in range(3):
	l.append(list(map(int, input().split())))
s1 = 0
for i in range(3):
	s1 = s1 + l[i][0]
s2 = sum(l[2])
if s2 > s1:
	l[0][0] = (sum(l[1]) + s2 - s1) // 2
	l[2][2] = (sum(l[1]) + s1 - s2) // 2
	l[1][1] = sum(l[0]) - sum(l[1])
else:
	l[0][0] = (sum(l[1]) + s2 - s1) // 2
	l[2][2] = (sum(l[1]) + s1 - s2) // 2
	l[1][1] = sum(l[0]) - sum(l[1])
for i in range(3):
	print(l[i][0], end=' ')
	print(l[i][1], end=' ')
	print(l[i][2])


(a, b, c) = map(int, input().split())
(r, s, t) = map(int, input().split())
(x, y, z) = map(int, input().split())
s = (2 * c + b - r) // 2
a = s + r + t - b - c
z = s + r + t - x - y
print(a, b, c)
print(r, s, t)
print(x, y, z)


r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))
temp1 = r1[1] + r1[2]
temp2 = r2[0] + r2[2]
temp3 = r3[0] + r3[1]
x = int((temp2 + temp3 - temp1) / 2)
y = int((-temp2 + temp3 + temp1) / 2)
z = int((temp2 - temp3 + temp1) / 2)
r1[0] = x
r2[1] = y
r3[2] = z
print(*r1)
print(*r2)
print(*r3)


(r1c1, r1c2, r1c3) = map(int, input().split())
(r2c1, r2c2, r2c3) = map(int, input().split())
(r3c1, r3c2, r3c3) = map(int, input().split())
for i in range(10 ** 5 + 1):
	if i + r1c2 + r1c3 == i + r2c1 + r3c1:
		sum = i + r1c2 + r1c3
		b = sum - (r1c2 + r3c2)
		if b + r2c1 + r2c3 == b + r1c3 + r3c1:
			if sum - (i + b) == sum - (r1c3 + r2c3):
				r1c1 = i
				r2c2 = b
				r3c3 = sum - (i + b)
				break
print(r1c1, r1c2, r1c3)
print(r2c1, r2c2, r2c3)
print(r3c1, r3c2, r3c3)


import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))
firstrow = get_ints()
secondrow = get_ints()
thirdrow = get_ints()
getmin = min(firstrow[1], firstrow[2], secondrow[0], secondrow[2], thirdrow[0], thirdrow[1])
diagonal = getmin + firstrow[2] + thirdrow[0]
if diagonal % 3 == 0:
	secondrow[1] = getmin
	firstrow[0] = diagonal - firstrow[1] - firstrow[2]
	thirdrow[2] = diagonal - thirdrow[0] - thirdrow[1]
else:
	diff = diagonal % 3
	diagonal += 3 - diff
	firstrow[0] = diagonal - firstrow[1] - firstrow[2]
	thirdrow[2] = diagonal - thirdrow[0] - thirdrow[1]
	secondrow[1] = diagonal - secondrow[0] - secondrow[2]
while firstrow[0] + secondrow[1] + thirdrow[2] != diagonal:
	diagonal += 3
	firstrow[0] = diagonal - firstrow[1] - firstrow[2]
	thirdrow[2] = diagonal - thirdrow[0] - thirdrow[1]
	secondrow[1] = diagonal - secondrow[0] - secondrow[2]
strs = str(firstrow[0]) + ' ' + str(firstrow[1]) + ' ' + str(firstrow[2])
print(strs)
strs = str(secondrow[0]) + ' ' + str(secondrow[1]) + ' ' + str(secondrow[2])
print(strs)
strs = str(thirdrow[0]) + ' ' + str(thirdrow[1]) + ' ' + str(thirdrow[2])
print(strs)


arr = []
s = 0
for i in range(3):
	a = list(map(int, input().split()))
	arr.append(a)
	s += sum(a)
s = s // 2
for i in range(3):
	arr[i][i] = s - sum(arr[i])
	print(*arr[i])


def main():
	square = []
	INF = int(100000.0)
	for _ in range(3):
		square.append([int(i) for i in input().split()])
	for first in range(1, INF + 1):
		s = first + square[0][1] + square[0][2]
		second = s - square[1][0] - square[1][2]
		third = s - square[2][0] - square[2][1]
		square[0][0] = first
		square[1][1] = second
		square[2][2] = third
		if second <= 0 or third <= 0 or second > INF or (third > INF):
			continue
		if square[0][0] + square[1][0] + square[2][0] == square[0][1] + square[1][1] + square[2][1] == square[0][2] + square[1][2] + square[2][2] == square[2][0] + square[1][1] + square[0][2] == square[0][0] + square[1][1] + square[2][2] == s:
			print(*square[0])
			print(*square[1])
			print(*square[2])
			break
		square[0][0] = square[1][1] = square[2][2] = 0
main()


import sys

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

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

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

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
(_, a1, a2) = rinput()
(b1, _, b2) = rinput()
(c1, c2, _) = rinput()
print((b2 + c2) // 2, a1, a2)
print(b1, (a2 + c1) // 2, b2)
print(c1, c2, (a1 + b1) // 2)


import sys
import bisect
import math
from collections import defaultdict
from collections import deque
from collections import Counter
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return input()

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 [[val for i in range(n)] for j in range(m)]
(x, a, b) = sp()
(c, y, d) = sp()
(e, f, z) = sp()
for i in range(1, pow(10, 5) + 1):
	y = i
	x = c + d + y - (a + b)
	z = c + d + y - (e + f)
	if x + y + z == x + a + b and x + y + z == y + c + d and (x + y + z == z + e + f) and (x + y + z == e + b + y) and (x + y + z == x + c + e) and (x + y + z == a + y + f) and (x + y + z == b + d + z):
		break
print(x, a, b)
print(c, y, d)
print(e, f, z)


l = []
for i in range(3):
	l.append(list(map(int, input().split())))
c1 = l[1][0] + l[2][0]
c2 = l[0][1] + l[2][1]
c3 = l[1][2] + l[0][2]
l[0][0] = (c2 + c3 - c1) // 2
l[1][1] = (c1 + c3 - c2) // 2
l[2][2] = (c2 + c1 - c3) // 2
for i in range(3):
	print(*l[i])


import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

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

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

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def revn(n):
	m = 0
	while n > 0:
		m = m * 10 + n % 10
		n = n // 10
	return m
ms = [li() for i in range(3)]
ms[0][0] = int((ms[0][2] + ms[2][0] + ms[2][1] - ms[1][0]) / 2)
ms[1][1] = int((ms[0][2] + ms[2][0] * 3 + ms[2][1] - ms[1][0]) / 2 - ms[1][2])
ms[2][2] = int((ms[0][2] + ms[2][0] - ms[2][1] + ms[1][0]) / 2)
for i in range(3):
	print(wr(ms[i]))


from sys import stdin, stdout
from collections import Counter

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

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

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
from math import ceil
matrix = []
for i in range(3):
	matrix.append(ai())
matrix[0][0] = (matrix[2][1] + matrix[1][2]) // 2
matrix[1][1] = (matrix[0][2] + matrix[2][0]) // 2
matrix[2][2] = (matrix[0][1] + matrix[1][0]) // 2
for i in matrix:
	print(*i)


import os, sys
from io import BytesIO, IOBase
from collections import deque, Counter, defaultdict as dft
from heapq import heappop, heappush
from math import log, sqrt, factorial, cos, tan, sin, radians, log2, ceil, floor
from bisect import bisect, bisect_left, bisect_right
from decimal import *
import sys, threading
from itertools import permutations, combinations
from copy import deepcopy
input = sys.stdin.readline
ii = lambda : int(input())
si = lambda : input().rstrip()
mp = lambda : map(int, input().split())
ms = lambda : map(str, input().strip().split(' '))
ml = lambda : list(mp())
mf = lambda : map(float, input().split())
alphs = 'abcdefghijklmnopqrstuvwxyz'

def solve():
	grid = []
	for _ in range(3):
		grid.append(ml())
	f1 = sum(grid[0])
	f2 = sum(grid[1])
	f3 = sum(grid[2])
	y = (f1 + f2 - f3) // 2
	x = f1 - y
	z = x + f2 - f1
	grid[0][0] = z
	grid[1][1] = x
	grid[2][2] = y
	for l in grid:
		print(*l)
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
tc = 1
for i in range(tc):
	solve()


a = [list(map(int, input().split())) for i in range(3)]
a[0][0] = int((sum(a[1]) + sum(a[2]) - sum(a[0])) / 2)
sum_1 = sum(a[0])
a[1][1] = sum_1 - sum(a[1])
a[2][2] = sum_1 - sum(a[2])
for i in range(3):
	print(a[i][0], a[i][1], a[i][2])


def main():

	def is_valid(grid):
		if sum(grid[0]) != sum(grid[1]) or sum(grid[1]) != sum(grid[2]):
			return False
		if grid[0][0] + grid[1][1] + grid[2][2] != grid[0][2] + grid[1][1] + grid[2][0]:
			return False
		return True
	grid = []
	for i in range(3):
		grid.append(list(map(int, input().split(' '))))
	m = [sum(grid[i]) for i in range(3)]
	for i in range(int(1000000.0)):
		grid[0][0] = i - sum(grid[0])
		grid[1][1] = i - sum(grid[1])
		grid[2][2] = i - sum(grid[2])
		if is_valid(grid) and grid[0][0] != 0:
			break
		grid[0][0] = 0
		grid[1][1] = 0
		grid[2][2] = 0
	for i in range(3):
		print(' '.join(list(map(str, grid[i]))))
main()


(_, a, b) = [int(x) for x in input().split()]
(a1, _, b1) = [int(x) for x in input().split()]
(a2, b2, _) = [int(x) for x in input().split()]
y = (a1 + b1 + _) / 2
p = y + a + b2 + _
x = abs(a1 + a2 + _ - p)
z = abs(b1 + b + _ - p)
print(int(x), a, b)
print(a1, int(y), b1)
print(a2, b2, int(z))


l1 = []
l2 = []
s = 0
for _ in range(3):
	li = list(map(int, input().split()))
	l1.append(li)
	x = sum(li)
	s += x
	l2.append(x)
s = s // 2
for i in range(3):
	for j in range(3):
		if i == j:
			l1[i][j] = s - l2[i]
		print(l1[i][j], end=' ')
	print()


x1 = input().split(' ')
x2 = input().split(' ')
x3 = input().split(' ')
x11 = int(x1[0])
x12 = int(x1[1])
x13 = int(x1[2])
x21 = int(x2[0])
x22 = int(x2[1])
x23 = int(x2[2])
x31 = int(x3[0])
x32 = int(x3[1])
x33 = int(x3[2])
x11 = int((x32 + 2 * x31 - x12) / 2)
x33 = int((x12 - x32 + x13 * 2) / 2)
sum = x11 + x12 + x13
x22 = int(sum - x21 - x23)
print(str(x11) + ' ' + str(x12) + ' ' + str(x13))
print(str(x21) + ' ' + str(x22) + ' ' + str(x23))
print(str(x31) + ' ' + str(x32) + ' ' + str(x33))


grid = [list(map(int, input().split())) for i in range(3)]
maxx = max(grid[1][0] + grid[2][0], grid[0][1] + grid[2][1], grid[0][2] + grid[1][2]) + 1
grid[0][0] = maxx - (grid[1][0] + grid[2][0])
grid[1][1] = maxx - (grid[0][1] + grid[2][1])
grid[2][2] = maxx - (grid[0][2] + grid[1][2])
total = grid[1][0] + grid[2][0] + grid[0][0]
while total - (grid[0][0] + grid[1][1] + grid[2][2]) != 0:
	grid[0][0] += 1
	grid[1][1] += 1
	grid[2][2] += 1
	total += 1
for row in grid:
	print(*row)


[A, B, C] = map(int, input().split())
[D, E, F] = map(int, input().split())
[G, H, I] = map(int, input().split())
somme = int((B + C + D + F + G + H) / 2)
A = somme - B - C
E = somme - D - F
I = somme - G - H
print(A, B, C)
print(D, E, F)
print(G, H, I)


Y = lambda : list(map(int, input().split()))
ans = list()
(a, b) = ([0] * 3, [])
for i in range(3):
	ans.append(Y())
	a[i] += sum(ans[i])
mx = max(a) + 1
while True:
	b = [mx - a[i] for i in range(3)]
	if sum(b) == mx:
		break
	mx += 1
for i in range(3):
	ans[i][i] = b[i]
print('\n'.join([' '.join(['{}'.format(i) for i in row]) for row in ans]))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
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 JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

class Prime:

	def __init__(self, n):
		self.M = m = int(math.sqrt(n)) + 10
		self.A = a = [True] * m
		a[0] = a[1] = False
		self.T = t = [2]
		for j in range(4, m, 2):
			a[j] = False
		for i in range(3, m, 2):
			if not a[i]:
				continue
			t.append(i)
			for j in range(i * i, m, i):
				a[j] = False
		self.ds_memo = {}
		self.ds_memo[1] = set([1])

	def is_prime(self, n):
		return self.A[n]

	def division(self, n):
		d = collections.defaultdict(int)
		for c in self.T:
			while n % c == 0:
				d[c] += 1
				n //= c
			if n < 2:
				break
		if n > 1:
			d[n] += 1
		return d.items()

	def divisions(self, n):
		if n in self.ds_memo:
			return self.ds_memo[n]
		for c in self.T:
			if n % c == 0:
				rs = set([c])
				for cc in self.divisions(n // c):
					rs.add(cc)
					rs.add(cc * c)
				self.ds_memo[n] = rs
				return rs
		rs = set([1, n])
		self.ds_memo[n] = rs
		return rs

def main():
	t = 1
	rr = []
	for _ in range(t):
		a = [LI() for _ in range(3)]
		b = [sum(_) for _ in a]
		t = max(b) + 1
		k = 0
		for (i, c) in enumerate(b):
			a[i][i] = t - c
			k += t - c
		u = sum(a[0])
		s = (u - k) // 2
		for i in range(3):
			a[i][i] += s
		rr.append(JAA(a, '\n', ' '))
	return JA(rr, '\n')
print(main())