Problem:
 Score : 100 points    Problem Statement A 3×3 grid with a integer written in each square, is called a magic square if and only if the integers in each row, the integers in each column, and the integers in each diagonal (from the top left corner to the bottom right corner, and from the top right corner to the bottom left corner), all add up to the same sum.  You are given the integers written in the following three squares in a magic square:   The integer A at the upper row and left column  The integer B at the upper row and middle column  The integer C at the middle row and middle column   Determine the integers written in the remaining squares in the magic square.  It can be shown that there exists a unique magic square consistent with the given information.      Constraints  0 \leq A, B, C \leq 100         Input The input is given from Standard Input in the following format:  A  B  C       Output Output the integers written in the magic square, in the following format:  X_{1,1}  X_{1,2}  X_{1,3}  X_{2,1}  X_{2,2}  X_{2,3}  X_{3,1}  X_{3,2}  X_{3,3}   where X_{i,j} is the integer written in the square at the i -th row and j -th column.        Sample Input 1 8
3
5      Sample Output 1 8 3 4
1 5 9
6 7 2       Sample Input 2 1
1
1      Sample Output 2 1 1 1
1 1 1
1 1 1

Solution (Python):
a=int(input())
b=int(input())
c=int(input())
d=c*3-a-b
g=c*2-d
h=c*2-b
i=c*2-a
e=c*3-a-g
f=c*3-d-i
print(a,b,d)
print(e,c,f)
print(g,h,i)

Solution (Python):
a=int(input())
b=int(input())
c=int(input())
d=2*c-(a+b)
m=[[a,b,c+d],[b+d+d,c,a-d],[c-d,a+d,b+d]]
for x in m:print(*x)

Solution (Python):
def examA():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x
    def lcm(x, y):
        return x * y // gcd(x, y)
    N, Z = LI()
    A = LI()
    F = set()
    for a in A:
        F.add(gcd(a,Z))
    
    ans = 1
    for f in F:
        ans = lcm(f,ans)

    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = [[0]*3 for _ in range(3)]
    ans[0][0] = I()
    ans[0][1] = I()
    ans[1][1] = I()
    center = ans[1][1]
    ans[2][2] = center*2-ans[0][0]
    ans[0][2] = center*3-sum(ans[0])
    ans[1][2] = center*3-ans[0][2]-ans[2][2]
    ans[1][0] = center*2-ans[1][2]
    ans[2][0] = center*3-ans[1][0]-ans[0][0]
    ans[2][1] = center*3-ans[2][0]-ans[2][2]
    for v in ans:
        print(" ".join(map(str,v)))
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

from decimal import Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):
a = int(input())
b = int(input())
c = int(input())
print(a, b, 3*c-a-b)
print(-2*a-b+4*c, c, 2*a+b-2*c)
print(a+b-c, 2*c-b, 2*c-a)

Solution (Python):
A=int(input())
B=int(input())
C=int(input())

print(A,B,3*C-A-B)
print(4*C-2*A-B,C,2*A+B-2*C)
print(A+B-C,2*C-B,2*C-A)

Solution (Python):
a=int(input())
b=int(input())
c=int(input())

li1=[a,b,3*c-a-b]
li2=[4*c-2*a-b,c,2*a+b-2*c]
li3=[a+b-c,2*c-b,2*c-a]
print(*li1)
print(*li2)
print(*li3)

Solution (Python):
def main():
    A = int(input())
    B = int(input())
    C = int(input())
    X = [[0] * 3 for _ in range(3)]
    X[0][0] = A
    X[0][1] = B
    X[1][1] = C
    X[2][0] = A + B - C
    X[2][2] = B + C - X[2][0]
    total = A + C + X[2][2]
    X[0][2] = total - A - B
    X[1][0] = total - A - X[2][0]
    X[1][2] = total - X[1][0] - C
    X[2][1] = total - B - C
    for i in range(3):
        print(*X[i])


if __name__ == "__main__":
    main()

Solution (Python):
a=int(input())
b=int(input())
c=int(input())
print(a,b,-a-b+3*c)
print(-2*a-b+4*c,c,2*a+b-2*c)
print(a+b-c,-b+2*c,-a+2*c)

Solution (Python):
a = int(input())
b = int(input())
c = int(input())
print(a, b, 3*c-a-b)
print(4*c-2*a-b, c, 2*a+b-2*c)
print(a+b-c, 2*c-b, 2*c-a)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

a = INT()
b = INT()
c = INT()

grid = list2d(3, 3, 0)
grid[0][0] = a
grid[0][1] = b
grid[1][1] = c

for i in range(301):
    grid[0][2] = i - a - b
    grid[2][2] = i - a - c
    grid[2][1] = i - b - c
    grid[1][2] = i - grid[0][2] - grid[2][2]
    grid[1][0] = i - grid[1][1] - grid[1][2]
    grid[2][0] = i - grid[0][0] - grid[1][0]
    if grid[2][0] == i - grid[1][1] - grid[0][2] \
            and grid[2][0] == i - grid[2][1] - grid[2][2]:
        for i in range(3):
            print(*grid[i])
        exit()

Solution (Python):
a,b,c=[int(input()) for _ in range(3)]
s=3*c
print(a,b,s-a-b)
print(2*s-2*a-b-2*c,c,2*a+b+c-s)
print(a+b+2*c-s,s-b-c,s-a-c)

Solution (Python):
a, b, c = [int(input()) for _ in range(3)]
for i1 in range(101):
  s = a + b + i1
  i6 = s - a - c
  i3 = s - i1- i6
  i2 = s - c - i3
  i4 = s - a - i2
  i5 = s - b - c
  li = [[a,b,i1],[i2,c,i3],[i4,i5,i6]]
  if all([sum(i) == s for i in li]) and all([sum(i) == s for i in zip(*li)]) and sum([i1,c,i4]) == s:
    for i in li: 
      print(*i)

Solution (Python):
a = int(input())
b = int(input())
c = int(input())
s = 3 * c

l = [
    [a, b, s-a-b],
    [2*s-2*a-b-2*c, c, 2*a+b+c-s],
    [a+b+2*c-s, s-b-c, s-a-c]
]

for i in l:
    print(*i)

Solution (Python):
a, b, e = int(input()), int(input()), int(input())

n = e*3
c = n - a - b
h = n - b - e
g = n - e - c
d = n - a - g
f = n - e - d
i = n - a - e
print(a,b,c)
print(d,e,f)
print(g,h,i)

Solution (Python):
def main():

    X11 = int(input())
    X12 = int(input())
    X22 = int(input())
    X13 = 0
    while True:
        v = X11 + X12 + X13 
        X31 = v - X13 - X22 
        X21 = v - X11 - X31 
        X23 = v - X21 - X22 
        X33 = v - X13 - X23 
        X32 = v - X12 - X22 

        if X31 + X32 + X33 == v and X11 + X22 + X33 == v: 
            print(" ".join(map(str, [X11, X12, X13])))
            print(" ".join(map(str, [X21, X22, X23])))
            print(" ".join(map(str, [X31, X32, X33])))
            break
        X13 += 1

if __name__ == '__main__':
    main()

Solution (Python):
r11 = int(input())
r12 = int(input())
r22 = int(input())
r33 = r22 * 2 - r11
r32 = r22 * 2 - r12
r31 = r22 * 3 - r33 - r32
r21 = r22 * 3 - r11 - r31
r13 = r22 * 3 - r11 - r12
r23 = r22 * 3 - r13 - r33

print(r11, r12, r13)
print(r21, r22, r23)
print(r31, r32, r33)

Solution (Python):
a=int(input())
b=int(input())
c=int(input())
print(a,b,3*c-a-b)
print(4*c-2*a-b,c,-2*c+2*a+b)
print(a+b-c,2*c-b,2*c-a)

Solution (Python):
from numpy.linalg import solve
 
a,b,c = [int(input()) for _ in range(3)] 
  
left = [[1,0,0,0,0,0,-1],
        [0,1,1,0,0,0,-1],
        [0,0,0,1,1,1,-1],
        [0,1,0,1,0,0,-1],
        [0,0,0,0,1,0,-1],
        [0,0,0,0,0,1,-1],
        [1,0,0,1,0,0,-1]]
 
right = [-a-b,-c,0,-a,-b-c,-a-c,-c]
 
l = solve(left, right)
u,v,w,x,y,z,s = map(int,l)
print(a,b,u)
print(v,c,w)
print(x,y,z)

Solution (Python):
A = int(input())
B = int(input())
C = int(input())

print(A, B, 3*C-A-B)
print(4*C-2*A-B, C, 2*A+B-2*C)
print(A+B-C, 2*C-B, 2*C-A)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

A,B,E = map(int,sys.stdin.readlines())

S = 3 * E
H = S-B-E
I = S-A-E
C = S-A-B
G = S-C-E
D = S-A-G
F = S-C-I

print(A,B,C)
print(D,E,F)
print(G,H,I)

Solution (Python):
a=int(input())
b=int(input())
c=int(input())
d=2*c-(a+b)
m=[[a,b,c+d],[b+d+d,c,a-d],[c-d,a+d,b+d]]
for x in m:print(*x)

Solution (Python):



def main():
    a = int(input())
    b = int(input())
    e = int(input())
    g = a + b - e
    i = b + e - g
    f = a + g - e
    c = a + i - g
    d = b + c - g
    h = a + d - i

    print(a, b, c)
    print(d, e, f)
    print(g, h, i)


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    a = int(input())
    b = int(input())
    e = int(input())
    g = a + b - e
    i = b + e - g
    f = a + g - e
    c = a + i - g
    d = b + c - g
    h = a + d - i

    print(a, b, c)
    print(d, e, f)
    print(g, h, i)


if __name__ == '__main__':
    main()

Solution (Python):
Xss = [[0]*(3) for _ in range(3)]
Xss[0][0] = int(input())
Xss[0][1] = int(input())
Xss[1][1] = int(input())

S = Xss[1][1] * 3

Xss[0][2] = S - Xss[0][0] - Xss[0][1]
Xss[2][1] = S - Xss[0][1] - Xss[1][1]
Xss[2][2] = S - Xss[0][0] - Xss[1][1]
Xss[1][2] = S - Xss[0][2] - Xss[2][2]
Xss[1][0] = S - Xss[1][1] - Xss[1][2]
Xss[2][0] = S - Xss[2][1] - Xss[2][2]

for Xs in Xss:
    print(*Xs)

Solution (Python):
from collections import deque
def isMahojin(jin):
  sigma = sum(jin[0])
  for i in range(3):
    if sum(jin[i]) != sigma:
      return False
    if sum([jin[k][i] for k in range(3)]) != sigma:
      return False
  if sum([jin[i][i] for i in range(3)]) != sigma:
    return False
  if sum([jin[2-i][i] for i in range(3)]) != sigma:
    return False
  return True

jin = [[0]*3 for _ in range(3)]
jin[0][0] = int(raw_input())
jin[0][1] = int(raw_input())
jin[1][1] = int(raw_input())
s = 1
while True:
  jin[0][2] = s - jin[0][0]-jin[0][1]
  jin[2][2] = s - jin[0][0]-jin[1][1]
  jin[2][1] = s - jin[0][1]-jin[1][1]
  jin[1][2] = s - jin[0][2]-jin[2][2]
  jin[2][0] = s - jin[2][1]-jin[2][2]
  jin[1][0] = s - jin[0][0]-jin[2][0]
  if isMahojin(jin):
    break
  s += 1
for i in range(3):
    print jin[i][0],jin[i][1],jin[i][2]

Solution (Python):
import sys

def check(matrix):
    S = sum(m[0])
    for i in range(3):
        if S != sum(m[i]):
            return False
    for j in range(3):
        if S != (m[0][j] + m[1][j] + m[2][j]):
            return False
    if S != (m[0][0] + m[1][1] + m[2][2]):
        return False
    if S != (m[0][2] + m[1][1] + m[2][0]):
        return False
    return True
    
def print_matrix(matrix):
    for i in range(3):
        print(" ".join(list(map(str, matrix[i]))))

m = [[None for __ in range(3)] for _ in range(3)]
m[0][0] = int(sys.stdin.readline().strip())
m[0][1] = int(sys.stdin.readline().strip())
m[1][1] = int(sys.stdin.readline().strip())

a = m[0][0]
b = m[0][1]
c = m[1][1]

for n in range(100+1):
    S = a + b + n
    m[0][2] = n
    m[2][0] = (S - n - c)
    m[2][1] = (S - b - c)
    m[1][0] = (S - a - m[2][0])
    m[2][2] = (S - a - c)
    m[1][2] = (S - m[1][0] - m[1][1])
    if check(m):
        print_matrix(m)

Solution (Python):
a=int(input())
b=int(input())
c=int(input())
print(a,b,-a-b+3*c)
print(-2*a-b+4*c,c,2*a+b-2*c)
print(a+b-c,-b+2*c,-a+2*c)

Solution (Python):
a = int(input())
b = int(input())
c = int(input())
d = 3*c-a-b
print(a,b,d)
print(c-a+d,c,a+c-d)
print(a+b-c,2*c-b,2*c-a)

Solution (Python):
A,B,C = int(input()),int(input()),int(input())

for n in range(-300,301):
    ans = [[A,B,n],[0,C,0],[0,0,0]]
    s = sum(ans[0])
    ans[2][1] = s - B - C
    ans[2][2] = s - C - A
    ans[1][2] = s - n - ans[2][2]
    ans[1][0] = s - C - ans[1][2]
    ans[2][0] = s - A - ans[1][0]
    if s == sum(ans[2]) == ans[0][2] + ans[1][1] + ans[2][0]:
        for row in ans:
            print(' '.join(map(str,row)))
        break

Solution (Python):
a = int(input())
b = int(input())
c = int(input())
s = 3*c
alpha = s-(b+c)
beta = s-(c+a)
gamma = s-(a+b)
delta = s-(alpha+beta)
print(a,b,gamma)
print((s-(a+delta)),c,(s-(beta+gamma)))
print(delta,alpha,beta)

Solution (Python):
a = int(input())
b = int(input())
c = int(input())

x = 3*c-a-b
print(a,b,x)
print(b-2*c+2*x,c,a+c-x)
print(2*c-x,a-c+x,b-c+x)

Solution (Python):
a=int(input())
b=int(input())
c=int(input())
x=[[0,0,0] for _ in range(3)]
for i in range(-300,301):
    x[0][0]=a
    x[0][1]=b
    x[1][1]=c
    x[0][2]=i-a-b
    x[2][2]=i-a-c
    x[2][1]=i-b-c
    x[1][2]=i-x[0][2]-x[2][2]
    x[1][0]=i-c-x[1][2]
    x[2][0]=i-x[2][1]-x[2][2]
    ok = True
    for j in range(3):
        t=0
        s=0
        for k in range(3):
            t+=x[j][k]
            s+=x[k][j]
        ok = ok and (t==i) and (s==i)
    ok = ok and (x[0][0]+x[1][1]+x[2][2]==i) and (x[0][2]+x[1][1]+x[2][0]==i)
    if not ok:
        continue
    for j in range(3):
        print(x[j][0],x[j][1],x[j][2])
    break

Solution (Python):
a=input()
b=input()
c=input()
print a, b, 3*c-a-b
print 4*c-2*a-b, c, 2*a+b-2*c
print a+b-c, 2*c-b, 2*c-a

Solution (Python):
a=int(raw_input())
b=int(raw_input())
c=int(raw_input())
x=[[0]*3 for _ in xrange(3)]
x[0][0]=a;x[0][1]=b;x[1][1]=c
for i in xrange(1000+1):
    x[0][2]=i
    msum=a+b+i
    x[2][1]=msum-x[0][1]-x[1][1]
    x[2][2]=msum-x[0][0]-x[1][1]
    if msum-x[2][1]-x[2][2]==msum-x[1][1]-x[0][2]:
        x[2][0]=msum-x[2][1]-x[2][2]
    else:
        continue
    x[1][0]=msum-x[0][0]-x[2][0]
    if msum-x[0][2]-x[2][2]==msum-x[1][0]-x[1][1]:
        x[1][2]=msum-x[0][2]-x[2][2]
    else:
        continue
    for j in xrange(3):
        print(" ".join(map(str,x[j])))
    break

Solution (Python):

import itertools
a = int(input())
b = int(input())
c = int(input())
k = 3*c
f = [
        [             a,      b,     k-a-b ],
        [ 2*k-2*a-b-2*c,      c, 2*a+b+c-k ],
        [     a+b+2*c-k,  k-b-c,     k-a-c ] ]
assert f[0][2] + f[1][1] + f[2][0] == k
for y in range(3):
    print(*f[y])

Solution (Python):
i=input
a=i();b=i();c=i()
d=2*c-a
e=c-b
print a,b,e+d
print 2*d-b,c,a+b-d
print a-e,c+e,d

Solution (Python):
A = int(input())
B = int(input())
C = int(input())

S = 3 * C
a = S - (A + B)
b = S - (2 * A + B - C)
c = 2 * A + B - 2 * C
d = A + B - C
e = S - (B + C)
f = S - (A + C)

print(" ".join(map(str, [A, B, a])))
print(" ".join(map(str, [b, C, c])))
print(" ".join(map(str, [d, e, f])))

Solution (Python):




a = int(input())
b = int(input())
e = int(input())
g = a + b - e
h = a + e - g
t = b + e + h
c = t - a - b
d = t - a - g
f = t - d - e
i = t - g - h
print("{} {} {}".format(a,b,c))
print("{} {} {}".format(d,e,f))
print("{} {} {}".format(g,h,i))

Solution (Python):
from sys import stdin
a = int(stdin.readline())
b = int(stdin.readline())
c = int(stdin.readline())
u = a+b-c 
y = 3*c - a - b
all = u + c + y 
w = all - a - c 
z = all - y - w 
x = all - a - u 
v = all - b - c 
print a,b,y 
print x,c,z 
print u,v,w

Solution (Python):
A = int(raw_input())
B = int(raw_input())
C = int(raw_input())
S = 3 * C
X13 = S - A - B
X21 = 2*S - 2*A- 2*C - B
X23 = 2*A + B + C - S
X31 = 2*C + A + B - S
X32 = S - B - C
X33 = S - A - C
print "%d %d %d" % (A, B, X13)
print "%d %d %d" % (X21, C, X23)
print "%d %d %d" % (X31, X32, X33)

Solution (Python):
A, B, C = input(), input(), input()
N = 3*C
print A, B, N-A-B
print N-2*A-B+C, C, 2*A+B-2*C
print A+B-C, N-B-C, N-A-C

Solution (Python):
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())

s = 3*c

print a,b,s-a-b
print s-(c+s-(s-a-b+s-a-c)),c,s-(s-a-b+s-a-c)
print a+b-c,s-b-c,s-a-c