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

Difficulty: interview

Starter code:

Solutions:
import sys
f = sys.stdin
#f = open("input.txt", "r")
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()

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

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


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


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



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



         


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


def __starting_point():
    main()
__starting_point()

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

# coding: utf-8
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 = []
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]))

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,b,c = list(map(int,input().split()))
d,e,f = list(map(int,input().split()))
g,h,i = list(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))


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

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

'''
def main():
    from sys import stdin,stdout
def __starting_point():
    main()
'''
#401
'''
def main():
    import sys
    a,b=map(int,sys.stdin.readline().split())
    if a>b:
        if a-b==1:
            s=''
            for i in range(a+b):
                if i&1:
                    s+='1'
                else:
                    s+='0'
        else:
            s='-1'
    elif b>a:
        if b<=2*(a+1):
            s=''
            if b-a==1:
                for i in range(a+b):
                    if i&1:
                        s+='0'
                    else:
                        s+='1'
            else:
                n=b-a-1
                i=0
                flag=0
                while i<a+b:
                    if flag&1:
                        s+='0'
                    else:
                        if n:
                            s+='11'
                            n-=1
                            i+=1
                        else:
                            s+='1'
                    i+=1
                    flag=~flag
        else:
            s='-1'
    else:
        s=''
        for i in range(a+b):
            if i&1:
                s+='1'
            else:
                s+='0'
    sys.stdout.write(s)
def __starting_point():
    main()
'''
#508B
'''
def main():
    import sys
    n=sys.stdin.readline().strip()
    lodd=int(n[-1])
    odd=0
    even=0
    s=''
    j=0
    for i in n:
        if ord(i)&1:
            odd+=1
        else:
            even+=1
            feven=int(i)
            feindex=j
            if(feven<lodd):
                break
        j+=1
    if even:
        for i in range(len(n)):
            if i==feindex:
                sys.stdout.write(n[-1])
            elif i==len(n)-1:
                sys.stdout.write(str(feven))
            else:
                sys.stdout.write(n[i])
    else:
        sys.stdout.write('-1')
def __starting_point():
    main()
'''
#447B
'''
def main():
    import sys
    s=sys.stdin.readline().strip()
    n=int(sys.stdin.readline())
    tup=tuple(map(int,sys.stdin.readline().split()))
    maxim=max(tup)
    score=0
    for i in range(len(s)):
        score+=(i+1)*tup[ord(s[i])-97]
    d=n*(2*len(s)+n+1)//2
    score+=maxim*d
    sys.stdout.write(str(score))
def __starting_point():
    main()
'''
#507B
'''
def main():
    from sys import stdin,stdout
    from math import ceil,sqrt
    def sqr(a):
        return a*a
    r,x,y,a,b=map(int,stdin.readline().split())
    mid=((x+a)/2,(y+b)/2)
    #print(mid)
    dis=sqrt(sqr(x-mid[0])+sqr(y-mid[1]))
    #print(dis)
    n=ceil(dis/r)
    stdout.write(str(n)+'\n')
def __starting_point():
    main()
'''
#454B
#SORT BY SHIFT
'''
def main():
    from sys import stdin,stdout
    n=int(stdin.readline())
    tup=tuple(map(int,stdin.readline().split()))
    minim=min(tup)
    maxim=max(tup)
    maximindex=tup.index(maxim)
    flag=1
    i=0
    pv=tup[-1]
    while i<n:
        if tup[i]<pv:
            if tup[i]==minim and pv==maxim:
                l=i+1
                while l<max(maximindex,n):
                    if tup[l]<tup[l-1]:
                        flag=0
                        break
                    l+=1
                break
            else:
                flag=0
                break
        pv=tup[i]
        i+=1
    #print(i)
    if flag:
        if i:
            stdout.write(str(n-i))
        else:
            stdout.write('0')
    else:
        stdout.write('-1')
def __starting_point():
    main()
'''
#450B
'''
def main():
    from sys import stdin,stdout
    MOD=int(1e9)+7
    x,y=map(int,stdin.readline().split())
    n=(int(stdin.readline())-1)%6
    tup=(x,y,y-x,-x,-y,x-y)
    stdout.write(str(tup[n]%MOD))
def __starting_point():
    main()
'''
#265B
'''
def main():
    from sys import stdin,stdout
    n=int(stdin.readline())
    ksum=n
    for i in range(n):
        x=int(stdin.readline())
        if i:
            if x<p:
                ksum+=1+(p-x)
                p=x
            else:
                ksum+=(1+x-p)
                p=x
        else:
            ksum+=x
            p=x
    stdout.write(str(ksum))
def __starting_point():
    main()
'''
#448B
'''
def main():
    from sys import stdin,stdout
    import collections
    s=stdin.readline().strip()
    t=stdin.readline().strip()
    if set(t).issubset(set(s)) and len(t)<=len(s):
        sp=0
        tp=0
        sc=collections.Counter(s)
        tc=collections.Counter(t)
        while sp<len(s) and tp<len(t):
            if s[sp]==t[tp]:
                tp+=1
                sp+=1
            else:
                sp+=1
        if tp==len(t):
            stdout.write('automaton')
        else:
            if len(t)==len(s):
                if sc!=tc:
                    stdout.write('need tree')
                else:
                    stdout.write('array')
            else:
                flag=1
                for i in sc:
                    if sc[i]<tc[i]:
                        flag=0
                if flag:
                    stdout.write('both')
                else:
                    stdout.write('need tree')
    else:
        stdout.write('need tree')
def __starting_point():
    main()
'''
#479C
'''
def main():
    from sys import stdin,stdout
    import collections
    myDic=collections.defaultdict(set)
    for _ in range(int(stdin.readline())):
        a,b=map(int,stdin.readline().split())
        myDic[a].add(b)
    index=max(myDic[min(myDic)])
    for i in sorted(myDic):
        if max(myDic[i])<index:
            index=i
        else:
            index=max(myDic[i])
    stdout.write(str(index))
    
def __starting_point():
    main()
'''
#455A
'''
def main():
    from sys import stdin,stdout
    import collections
    n=int(stdin.readline())
    tup=tuple(map(int,stdin.readline().split()))
    maxim=max(tup)
    cnt=collections.Counter(tup)
    f=[0,cnt[1]]
    for i in range(2,maxim+1):
        f.append(max(f[i-1],f[i-2]+cnt[i]*i))
    stdout.write(str(f[maxim]))
def __starting_point():
    main()
'''
#151A
'''
def main():
    from sys import stdin,stdout
    n,k,l,c,d,p,nl,np=map(int,stdin.readline().split())
    stdout.write(str(min((k*l//nl,c*d,p//np))//n))
def __starting_point():
    main()
'''
#313B
'''
def main():
    from sys import stdin,stdout
    s=stdin.readline().strip()
    tup=()
    for _ in range(int(stdin.readline())):
        a,b=map(int,stdin.readline().split())
        counter=0
        for i in range(a-1,b-1):
            if s[i]==s[i+1]:
                counter+=1
        tup+=(counter,)
    for i in tup:
        stdout.write(str(i)+'\n')
def __starting_point():
    main()
'''
#259B
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()

#!/usr/bin/env python3
# codeforces little elephant and magic square

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

'''
T = x + y + z
y + z = sum(Row1)
x + z = sum(Row2)
x + y = sum(Row3)

'''


"""http://codeforces.com/problemset/problem/259/B"""

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

def __starting_point():
    res = solve([list(map(int, input().split())) for _ in range(3)])
    for i in range(3):
        print(' '.join(map(str, res[i])))

__starting_point()

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
%d %d %d
%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




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

# Description of the problem can be found at http://codeforces.com/problemset/problem/259/B

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

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 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(1e6)):
        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()


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