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



Sample input:
8
3
5


Sample output:
8 3 4
1 5 9
6 7 2

Submission status: Wrong Answer

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

for X in range(301):
    if X-A-B>=0:
        if 2*A+B+C-X>=0:
            if X-A-C>=0:
                if X-B-C>=0:
                    if 2*C+A+B-X>=0:
                        if 2*X-2*A-2*C-B>=0:
                            break
print(A,B,X-A-B)
print(2*X-2*A-2*C-B,C,2*A+B+C-X)
print(2*C+A+B-X,X-B-C,X-A-C)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
a=int(input())
b=int(input())
c=int(input())
print(a,b,c)
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)

Submission status: Wrong Answer

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

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

for i in l:
    print(*i)

Submission status: Wrong Answer

Solution code:
def main():

    X11 = int(input())
    X12 = int(input())
    X22 = int(input())
    for X13 in range(0, 301):
        v = X11 + X12 + X13
        X31 = v - X13 - X22
        if X31 < 0: continue
        X21 = v - X11 - X31
        if X21 < 0: continue
        X23 = v - X21 - X22
        if X23 < 0: continue
        X33 = v - X13 - X23
        if X33 < 0: continue
        X32 = v - X12 - X22
        if X32 < 0: continue

        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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    a = int(input())
    b = int(input())
    c = int(input())

    # a b e
    # g c i
    # h d f

    for total in range(1000 + 1):
        d = total - (b + c)
        e = total - (a + b)
        f = total - (a + c)

        if 0 <= d and 0 <= e and 0 <= f:
            i = total - (e + f)
            h = total - (e + c)
            g = total - (a + h)

            if 0 <= i and 0 <= h and 0 <= g:
                if total == (d + f + h):
                    print(a, b, e)
                    print(g, c, i)
                    print(h, d, f)
                    exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    a = int(input())
    b = int(input())
    c = int(input())

    # a b e
    # g c i
    # h d f

    for total in range(1000 + 1):
        d = total - (b + c)
        e = total - (a + b)
        f = total - (a + c)

        if 0 <= d and 0 <= e and 0 <= f:
            i = total - (e + f)
            h = total - (e + c)
            g = total - (a + h)

            if 0 <= i and 0 <= h and 0 <= g:
                if total == (d + f + h) and total == (e + i + f) and total == (g + c + i) and total == (a + b + e) and total == (a + g + h) and total == (b + c + d) and total == (a + c + f) and total == (e + c + h):
                    print(a, b, e)
                    print(g, c, i)
                    print(h, d, f)
                    exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    a = int(input())
    b = int(input())
    c = int(input())

    # a b e
    # g c i
    # h d f

    for total in range(300 + 1):
        d = total - (b + c)
        e = total - (a + b)
        f = total - (a + c)

        if 0 <= d and 0 <= e and 0 <= f:
            i = total - (e + f)
            h = total - (e + c)
            g = total - (a + h)

            if 0 <= i and 0 <= h and 0 <= g:
                if total == (d + f + h) and total == (e + i + f) and total == (g + c + i) and total == (a + b + e) and total == (a + g + h) and total == (b + c + d) and total == (a + c + f) and total == (e + c + h):
                    print(a, b, e)
                    print(g, c, i)
                    print(h, d, f)
                    exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    a = int(input())
    b = int(input())
    c = int(input())

    # a b e
    # g c i
    # h d f

    for total in range(300 + 1):
        d = total - (b + c)
        e = total - (a + b)
        f = total - (a + c)

        if 0 <= d <= 100 and 0 <= e <= 100 and 0 <= f <= 100:
            i = total - (e + f)
            h = total - (e + c)
            g = total - (a + h)

            if 0 <= i <= 100 and 0 <= h <= 100 and 0 <= g <= 100:
                if total == (d + f + h) and total == (e + i + f) and total == (g + c + i) and total == (a + b + e) and total == (a + g + h) and total == (b + c + d) and total == (a + c + f) and total == (e + c + h):
                    print(a, b, e)
                    print(g, c, i)
                    print(h, d, f)
                    exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    a = int(input())
    b = int(input())
    c = int(input())

    # a b e
    # g c i
    # h d f

    for total in range(300 + 1):
        d = total - (b + c)
        e = total - (a + b)
        f = total - (a + c)

        if 0 <= d <= 100 and 0 <= e <= 100 and 0 <= f <= 100:
            i = total - (e + f)
            h = total - (e + c)
            g = total - (a + h)

            if 0 <= i <= 100 and 0 <= h <= 100 and 0 <= g <= 100:
                if total == (d + f + h) and total == (e + i + f) and total == (g + c + i):
                    print(a, b, e)
                    print(g, c, i)
                    print(h, d, f)
                    exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    a = int(input())
    b = int(input())
    c = int(input())

    # a b e
    # g c i
    # h d f

    for total in range(300 + 1):
        d = total - (b + c)
        e = total - (a + b)
        f = total - (a + c)

        if 0 <= d <= 100 and 0 <= e <= 100 and 0 <= f <= 100:
            i = total - (e + f)
            h = total - (e + c)
            g = total - (a + h)

            if 0 <= i <= 100 and 0 <= h <= 100 and 0 <= g <= 100:
                if total == (d + f + h) and total == (e + i + f):
                    print(a, b, e)
                    print(g, c, i)
                    print(h, d, f)
                    exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    a = int(input())
    b = int(input())
    c = int(input())

    # a b e
    # g c i
    # h d f

    for total in range(300 + 1):
        d = total - (b + c)
        e = total - (a + b)
        f = total - (a + c)

        if 0 <= d <= 100 and 0 <= e <= 100 and 0 <= f <= 100:
            i = total - (e + f)
            h = total - (e + c)
            g = total - (a + h)

            if 0 <= i <= 100 and 0 <= h <= 100 and 0 <= g <= 100:
                if total == (d + f + h):
                    print(a, b, e)
                    print(g, c, i)
                    print(h, d, f)
                    exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def check(m,s):
    if m[0][0] + m[1][1] + m[2][2] == s and m[0][2] + m[1][1] + m[2][0] == s:
        return True
    else:
        return False
import numpy as np
a = int(input())
b = int(input())
c = int(input())
m = np.zeros((3,3))
m[0][0] = a
m[0][1] = b
m[1][1] = c
g1 = a + b
g2 = a + c
g3 = b + c
s1 = max(g1,g2,g3)
s  = s1
while s < s1 + 101:
    x6 = s - g1
    if x6 < 0 or x6 > 100:
        s += 1
        continue
    else:
        m[0][2] = x6
    x4 = s - g2
    if x4 < 0 or x4 > 100:
        s += 1
        continue
    else:
        m[2][2] = x4
    x3 = s - g3
    if x3 < 0 or x3 > 100:
        s += 1
        continue
    else:
        m[2][1] = x3
    x2 = s - x4 -x3
    if x2 < 0 or x2 > 100:
        s += 1
        continue
    else:
        m[2][0] = x2
    x1 = s - a - x2
    if x1 < 0 or x1 > 100:
        s += 1
        continue
    else:
        m[1][0] = x1
    x5 = s - x4 - x6
    if x5 < 0 or x5 > 100:
        s += 1
        continue
    else:
        m[1][2] = x5
    if check(m,s):
        break
    
    s += 1
for i in range(3):
    result = str(int(m[i][0]))+" "+str(int(m[i][1]))+" "+str(int(m[i][2]))
    print(result)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=int(input())
c=int(input())
x=[[0,0,0] for _ in range(3)]
for i in range(3,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):
        for k in range(3):
            ok = ok and (1 <= x[j][k] <= 100)
    if not ok:
        continue
    for j in range(3):
        print(x[j][0],x[j][1],x[j][2])
    exit(0)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=int(input())
c=int(input())
x=[[0,0,0] for _ in range(3)]
for i in range(1,101):
    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):
        for k in range(3):
            ok = ok and (1 <= x[j][k] <= 100)
    if not ok:
        continue
    for j in range(3):
        print(x[j][0],x[j][1],x[j][2])
    exit(0)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import itertools
a = int(input())
b = int(input())
c = int(input())
for k in itertools.count():
    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 ] ]
    if min(sum(f, [])) >= 0:
        for y in range(3):
            print(*f[y])
        break

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import itertools
a = int(input())
b = int(input())
c = int(input())
for k in itertools.count():
    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 ] ]
    print(*f[0])
    print(*f[1])
    print(*f[2])
    break

Submission status: Wrong Answer

Solution code:
x11, x12, x22 = (int(input()) for _ in range(3))
sum = x11 + x12 + x22
x13, x32, x33 = sum-(x11+x12), sum-(x12+x22), sum-(x11+x12)
x23, x31 = sum-(x13+x33), sum-(x13+x22)
x21 = sum-(x22+x23) 
print('%d %d %d\n%d %d %d\n%d %d %d' % (x11,x12,x13,x21,x22,x23,x31,x32,x33))

Submission status: Wrong Answer

Solution code:
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
X1 = [A, B, X13]
X2 = [X21, C, X23]
X3 = [X31, X32, X33]
print X1
print X2
print X3

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))
    #print(F)
    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
"""

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
def main():

    X11 = int(input())
    X12 = int(input())
    X22 = int(input())
    X13 = 0
    while True:
        v = X11 + X12 + X13 # 1st row
        X31 = v - X13 - X22 # diag 2
        X21 = v - X11 - X31 # 1st col
        X23 = v - X21 - X22 # 2nd row
        X33 = v - X13 - X23 # 3rd col
        X32 = v - X12 - X22 # 2nd col

        if X31 + X32 + X33 == v and X11 + X22 + X33 == v: # 3rd row, diag 1
            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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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]

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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])

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
# A B c
# d E f
# g h i

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Runtime Error

Solution code:
a,b,c=map(int,input().split())
print(a,b,c)
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)

Submission status: Runtime Error

Solution code:
a,b,c=[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)

Submission status: Runtime Error

Solution code:

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

Submission status: Runtime Error

Solution code:
a,b,c = map(int, raw_input().split())

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

Submission status: Runtime Error

Solution code:
a,b,c = map(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