Problem:


Score: 300 points

Problem Statement

We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left.

According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j.

Determine if he is correct.  

Constraints

c_{i, j} \ (1 \leq i \leq 3, 1 \leq j \leq 3) is an integer between 0 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

c_{1,1} c_{1,2} c_{1,3}
c_{2,1} c_{2,2} c_{2,3}
c_{3,1} c_{3,2} c_{3,3}

Output

If Takahashi's statement is correct, print Yes; otherwise, print No.

Sample Input 1

1 0 1
2 1 2
1 0 1

Sample Output 1

Yes

Takahashi is correct, since there are possible sets of integers such as: a_1=0,a_2=1,a_3=0,b_1=1,b_2=0,b_3=1.

Sample Input 2

2 2 2
2 1 2
2 2 2

Sample Output 2

No

Takahashi is incorrect in this case.

Sample Input 3

0 8 8
0 8 8
0 8 8

Sample Output 3

Yes

Sample Input 4

1 8 6
2 9 7
0 7 7

Sample Output 4

No



Sample input:
1 0 1
2 1 2
1 0 1


Sample output:
Yes

Submission status: Accepted

Solution code:
l = list(list(map(int,input().split())) for i in range(3))
first = l[0][0]-l[0][1]
second = l[0][1]-l[0][2]
first1 = l[0][0]-l[1][0]
second2 = l[1][0]-l[2][0]

for k in range(3):
    if (l[k][0]-l[k][1] != first or l[k][1]-l[k][2] != second):
        print("No")
        exit()
for j in range(3):
    if (l[0][k]-l[1][k] != first1  or l[1][k]-l[2][k] != second2):
        print("No")
        exit()     
print("Yes")

Submission status: Accepted

Solution code:
c1 = list(map(int, input().split()))
c2 = list(map(int, input().split()))
c3 = list(map(int, input().split()))

for b1 in range(101):
    for b2 in range(101):
        for b3 in range(101):
            if c1[0] - b1 == c1[1] - b2 == c1[2] - b3:
                if c2[0] - b1 == c2[1] - b2 == c2[2] - b3:
                    if c3[0] - b1 == c3[1] - b2 == c3[2] - b3:
                        print("Yes")
                        exit()
else:
    print("No")

Submission status: Accepted

Solution code:

c1 = tuple(map(int,input().split()))
c2 = tuple(map(int,input().split()))
c3 = tuple(map(int,input().split()))

q = 0

adif = [c1[1]-c1[0],c1[2]-c1[1]]

bdif1 = int(c2[0]-c1[0])

bdif2 = int(c3[0]-c2[0])

acnt = 0

bdif = 0

if c2[1]-c2[0] != adif[0]:
    q = 1
    
if c2[2]-c2[1] != adif[1]:
    q = 1
    
if c3[1]-c3[0] != adif[0]:
    q = 1
    
if c3[2]-c3[1] != adif[1]:
    q = 1
    
if int(c2[1]-c1[1]) != bdif1:
    q = 1
    
if c2[2]-c1[2] != bdif1:
    q = 1
    
if c3[1]-c2[1] != bdif2:
    q = 1
    
if c3[2]-c2[2] != bdif2:
    q = 1
    
if q == 1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
if (sum(A)+sum(B)+sum(C))/3 == A[0]+B[1]+C[2] == A[2]+B[1]+C[0]:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

for i in range(3):
    for j in range(3):
        if c[i][j] != a[i]+b[j]:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
C = [list(map(int,input().split())) for _ in range(3)]
if C[1][0]-C[0][0]==C[1][1]-C[0][1]==C[1][2]-C[0][2] and C[2][0]-C[0][0]==C[2][1]-C[0][1]==C[2][2]-C[0][2] \
and C[0][1]-C[0][0]==C[1][1]-C[1][0]==C[2][1]-C[2][0] and C[0][2]-C[0][0]==C[1][2]-C[1][0]==C[2][2]-C[2][0]:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
A = []
for i in range(3):
  temp = list(map(int,input().split()))
  A.append(temp)

if A[0][0]+A[1][1] == A[0][1]+A[1][0] and \
A[0][1]+A[1][2] == A[0][2]+A[1][1] and \
A[1][0]+A[2][1] == A[1][1]+A[2][0] and \
A[1][1]+A[2][2] == A[1][2]+A[2][1]:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    C = [list(map(int, input().split())) for _ in range(3)]

    A = [0] * 3
    B = [0] * 3
    for i in range(3):
        B[i] = C[0][i] - A[0]

    for j in range(3):
        A[j] = C[j][0] - B[0]

    for i in range(3):
        for j in range(3):
            if A[i] + B[j] != C[i][j]:
                print("No")
                break
        else:
            continue
        break
    else:
        print("Yes")


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
c = [list(map(int, input().split())) for _ in range(3)]
dif_1 = c[0][1] - c[0][0]
dif_2 = c[0][2] - c[0][1]
dif_3 = c[1][0] - c[0][0]
dif_4 = c[2][0] - c[1][0]

if c[1][1] - c[1][0] != dif_1 or c[2][1] - c[2][0] != dif_1:
    print("No")
    exit()
elif c[1][2] - c[1][1] != dif_2 or c[2][2] - c[2][1] != dif_2:
    print("No")
    exit()
elif c[1][1] - c[0][1] != dif_3 or c[1][2] - c[0][2] != dif_3:
    print('No')
    exit()
elif c[2][2] - c[1][2] != dif_4 or c[2][1] - c[1][1] != dif_4:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
c1,c2,c3=map(int,input().split())
c4,c5,c6=map(int,input().split())
c7,c8,c9=map(int,input().split())
k=c2-c1
failflag=0
if (c5-c4)!=k or (c8-c7)!=k:
  failflag=1
k=c3-c2
if (c6-c5)!=k or (c9-c8)!=k:
  failflag=1
k=c4-c1
if (c5-c2)!=k or (c6-c3)!=k:
  failflag=1
k=c7-c4
if (c8-c5)!=k or (c9-c6)!=k:
  failflag=1
if failflag==0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
c1,c2,c3=map(int,input().split())
c4,c5,c6=map(int,input().split())
c7,c8,c9=map(int,input().split())
if c3-c2==c6-c5 and c6-c5==c9-c8 and c2-c1==c5-c4 and c5-c4==c8-c7 and c4-c1==c5-c2 and c5-c2==c6-c3 and c7-c4==c8-c5 and c8-c5==c9-c6:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
c = [list(map(int,input().split())) for x in range(3)]

a = [0]*3
b = [0]*3

for i in range(3):
    b[i] = c[0][i] - a[0]
a[1] = c[1][1] - b[1]
a[2] = c[2][2] - b[2]

for i in range(3):
    for j in range(3):
        if c[i][j] != a[i]+b[j]:
            print('No')
            exit()

print('Yes')

Submission status: Accepted

Solution code:
c=[list(map(int,input().split())) for i in range(3)]
for i in range(min(c[0])+1):
  b1=c[0][0]-i
  b2=c[0][1]-i
  b3=c[0][2]-i
  if c[1][0]-b1==c[1][1]-b2==c[1][2]-b3:
    if c[2][0]-b1==c[2][1]-b2==c[2][2]-b3:
      print("Yes")
      break
    else:
      continue
  else:
    continue
else:
  print("No")

Submission status: Accepted

Solution code:
#ABC088-C
grid = [list(map(int,input().split())) for _ in range(3)]
flg = True
b1 = grid[0][0]
b2 = grid[0][1]
b3 = grid[0][2]
if grid[1][0] - b1 == grid[1][1] - b2 == grid[1][2] - b3:
    a2 = grid[1][0] - b1
else:
    flg = False
if grid[2][0] - b1 == grid[2][1] - b2 == grid[2][2] - b3:
    a3 = grid[2][0] - b1
else:
    flg = False
    
if flg:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
c = [list(map(int, input().split())) for _ in range(3)]
if c[0][1]-c[0][0]!=c[1][1]-c[1][0]:
    print("No")
    exit()
if c[0][2]-c[0][0]!=c[1][2]-c[1][0]:
    print("No")
    exit()
if c[0][2]-c[0][1]!=c[1][2]-c[1][1]:
    print("No")
    exit()
if c[0][1]-c[0][0]!=c[2][1]-c[2][0]:
    print("No")
    exit()
if c[0][2]-c[0][0]!=c[2][2]-c[2][0]:
    print("No")
    exit()
if c[0][2]-c[0][1]!=c[2][2]-c[2][1]:
    print("No")
    exit()
    
if c[1][0]-c[0][0]!=c[1][1]-c[0][1]:
    print("No")
    exit()
if c[2][0]-c[0][0]!=c[2][1]-c[0][1]:
    print("No")
    exit()
if c[2][0]-c[1][0]!=c[2][1]-c[1][1]:
    print("No")
    exit()
if c[1][0]-c[0][0]!=c[1][2]-c[0][2]:
    print("No")
    exit()
if c[2][0]-c[0][0]!=c[2][2]-c[0][2]:
    print("No")
    exit()
if c[2][0]-c[1][0]!=c[2][2]-c[1][2]:
    print("No")
    exit() 
  
print("Yes")

Submission status: Accepted

Solution code:
s=[]
yoko=[]
ans="Yes"
for i in range(3):
  a, b, c=map(int, input().split())
  s.append([a,b,c])
  yoko.append([a-b, b-c, c-a])
if yoko[0]!=yoko[1] or yoko[1]!=yoko[2]:
  ans="No"
tate=[]
for i in range(3):
  tate.append([s[i][0]-s[i][1], s[i][1]-s[i][2], s[i][2]-s[i][0]])
if tate[0]!=tate[1] or tate[1]!=tate[2]:
  ans="No"
print(ans)

Submission status: Accepted

Solution code:
c11,c12,c13=list(map(int,input().split()))
c21,c22,c23=list(map(int,input().split()))
c31,c32,c33=list(map(int,input().split()))
for i in range(min(c11,c12,c13)+1):
  t1=c11-i
  t2=c12-i
  t3=c13-i
  if c21-t1==c22-t2 and c21-t1==c23-t3 and c31-t1==c32-t2 and c31-t1==c33-t3:
    print("Yes")
    break
else:
  print("No")

Submission status: Accepted

Solution code:
def main():
    c = [list(map(int, input().split())) for _ in range(3)]
    s1 = c[0][0] + c[1][1] + c[2][2]
    s2 = c[1][0] + c[2][1] + c[0][2]
    s3 = c[2][0] + c[0][1] + c[1][2]
    s4 = c[0][0] + c[1][2] + c[2][1]
    s5 = c[1][0] + c[2][2] + c[0][1]
    s6 = c[2][0] + c[0][2] + c[1][1]
    
    if s1 == s2 == s3 == s4 == s5 == s6:
        print('Yes')
    else:
        print('No')
    
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
r=range
M=[list(map(int,input().split())) for _ in r(3)]
for i in r(2):
  x=M[0][i]-M[0][i+1]
  y=M[i][0]-M[i+1][0]
  for j in r(3):
    if x!=M[j][i]-M[j][i+1] or y!=M[i][j]-M[i+1][j]:
      print('No')
      exit()
print('Yes')

Submission status: Accepted

Solution code:
c = [[int(i) for i in input().split()] for _ in range(3)]
x = 0
for i in range(2):
    if c[0][i] - c[0][i + 1] == c[1][i] - c[1][i + 1] == c[2][i] - c[2][i + 1]:
        x += 1
for i in range(2):
    if c[i][0] - c[i + 1][0] == c[i][1] - c[i + 1][1] == c[i][2] - c[i + 1][2]:
        x += 1
if x == 4:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
c = [list(map(int, input().split())) for i in range(3)]

if c[0][0]+c[1][0]-2*c[2][0]+c[0][1]+c[1][1]-2*c[2][1]-2*c[0][2]-2*c[1][2]+4*c[2][2] == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
C = [list(map(int, input().split())) for _ in range(3)]
if sum(sum(row) for row in C) == 3 * sum(C[i][i] for i in range(3)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

if __name__  == "__main__":
    c1 = list(map(int,input().split()))
    c2 = list(map(int,input().split()))
    c3 = list(map(int,input().split()))
    a1 = 0
    b1 = c1[0]
    b2 = c1[1]
    b3 = c1[2]
    b = [b1,b2,b3]
    a2 = c2[0] - b1 
    for i in range(3):
        d = c2[i] - b[i]
        if a2 != d:
            print("No")
            sys.exit()
    a3 = c3[0] - b1
    for i in range(3):
        d = c3[i] - b[i]
        if a3 != d:
            print("No")
            sys.exit()
    print("Yes")

Submission status: Accepted

Solution code:
cmatrix = []
for i in range(3):
  cmatrix.append(list(map(int, input().split())))
  
if(cmatrix[0][0]+ cmatrix[1][1] == cmatrix[0][1]+ cmatrix[1][0] and \
  cmatrix[0][1]+ cmatrix[1][2] == cmatrix[0][2]+ cmatrix[1][1] and \
  cmatrix[1][0]+ cmatrix[2][1] == cmatrix[1][1]+ cmatrix[2][0] and \
  cmatrix[1][1]+ cmatrix[2][2] == cmatrix[1][2]+ cmatrix[2][1]):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
m = [[0 for i in range(3)] for j in range(3)]
for i in range(3):
    m[i] = list(map(int, input().split()))

a1 = a2 = a3 = 0
b1, b2, b3 = m[0]
a2 = m[1][0] - b1
a3 = m[2][0] - b1

if ((m[1][1] != a2 + b2) or
    (m[1][2] != a2 + b3) or
    (m[2][1] != a3 + b2) or
    (m[2][2] != a3 + b3)):
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
def solve(c1_list, c2_list, c3_list):

    a1 = 0
    ans = "No"
    while a1 <= 100:
        b_list = [c - a1 for c in c1_list]

        a2 = len(set([c - b for c, b in zip(c2_list, b_list)]))
        a3 = len(set([c - b for c, b in zip(c3_list, b_list)]))

        if a2 == 1 and a3 == 1:
            ans = "Yes"
            break
        else:
            a1 += 1

    return ans

if __name__ == "__main__":
    c1_list = [int(i) for i in input().split()]
    c2_list = [int(i) for i in input().split()]
    c3_list = [int(i) for i in input().split()]
    print(solve(c1_list, c2_list, c3_list))

Submission status: Accepted

Solution code:
A = [tuple(map(int, input().split())) for i in range(3)]
for x, y in zip(A, A[1:]):
	if not (y[0] - x[0] == y[1] - x[1] == y[2] - x[2]):
		print("No")
		exit()
for x in range(2):
	if not (A[0][x+1] - A[0][x] == A[1][x+1] - A[1][x] == A[2][x+1] - A[2][x]):
		print("No")
		exit()
if A[0][0] + A[2][2] != A[0][2] + A[2][0]:
	print("No")
	exit()
print("Yes")

Submission status: Accepted

Solution code:
def main():
    a = [list(map(int, input().split())) for i in range(3)]
    if (a[1][0] - a[0][0] == a[1][1] - a[0][1]) \
        and (a[1][1] - a[0][1] == a[1][2] - a[0][2]) \
        and (a[2][0] - a[1][0] == a[2][1] - a[1][1]) \
        and (a[2][1] - a[1][1] == a[2][2] - a[1][2]) \
        and (a[0][1] - a[0][0] == a[1][1] - a[1][0]) \
        and (a[1][1] - a[1][0] == a[2][1] - a[2][0]) \
        and (a[0][2] - a[0][1] == a[1][2] - a[1][1]) \
        and (a[1][2] - a[1][1] == a[2][2] - a[2][1]):
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
c = [list(map(int, input().split())) for i in range(3)]
s = sum([sum(l) for l in c])
print('Yes' if s/3 == c[0][0] + c[1][1] + c[2][2] else 'No')

Submission status: Accepted

Solution code:
c1 = list(map(int, input().split()))
c2 = list(map(int, input().split()))
c3 = list(map(int, input().split()))
b = [0]*3
b[0] = c1[0]
b[1] = c1[1]
b[2] = c1[2]
C = c1+c2+c3

a = [0]*3

a[0] = 0
a[1] = C[3] - b[0]
a[2] = C[6] - b[0]



z = 0
for x in a:
    for y in b:
        if C[z] != x + y:
            print("No")
            exit()
        z += 1

print("Yes")

Submission status: Accepted

Solution code:
c11,c12,c13 = map(int,input().split())
c21,c22,c23 = map(int,input().split())
c31,c32,c33 = map(int,input().split())
if c11-c12  == c21-c22 and c11-c12 == c31-c32 and c12-c13 == c22-c23 and c12-c13 == c32-c33:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    grid = [lmi() for _ in range(3)]
    vertical = [[grid[i+1][j] - grid[i][j] for j in range(3)] for i in range(2)]
    horizontal = [[grid[i][j+1] - grid[i][j] for i in range(3)] for j in range(2)]
    # print(vertical)
    # print(horizontal)
    if len(list(set(vertical[0]))) == 1 and len(list(set(vertical[1]))) == 1 and len(list(set(horizontal[0]))) == 1 and len(list(set(horizontal[1]))) == 1:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
c = [list(map(int,input().split())) for i in range(3)]
a1 = 0
a2 = 0
a3 = 0
b1 = 0
b2 = 0
b3 = 0
m = min(c[0])
for i in range(m+1):
    a1 = i
    b1 = c[0][0]-a1
    b2 = c[0][1]-a2
    b3 = c[0][2]-a3
    if c[1][0]-b1 == c[1][1]-b2 == c[1][2]-b3:
        a2 = c[1][0]-b1
    else:
        continue
    if c[2][0]-b1 == c[2][1]-b2 == c[2][2]-b3:
        print('Yes')
        exit()
print('No')

Submission status: Accepted

Solution code:
C1 = list(map(int, input().split()))
C2 = list(map(int, input().split()))
C3 = list(map(int, input().split()))

if C1[1] + C2[0] - C1[0] == C2[1] and C1[1] + C3[0] - C1[0] == C3[1] and \
   C1[2] + C3[0] - C1[0] == C3[2] and C1[2] + C2[0] - C1[0] == C2[2] :
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
c = [list(map(int, input().split())) for _ in range(3)]
 
for i in range(2):
  for j in range(2):
    if c[i][j] - c[i][j+1] == c[i+1][j] - c[i+1][j+1]:
      pass
    else:
      print('No')
      exit()
      
print('Yes')

Submission status: Accepted

Solution code:
# ans

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

for i in range(2):
  for j in range(2):
    if c[i][j] - c[i][j+1] == c[i+1][j] - c[i+1][j+1]:
      pass
    else:
      print('No')
      exit()
      
print('Yes')

Submission status: Accepted

Solution code:
from itertools import chain, groupby


def flatten(list_of_lists):
    return chain.from_iterable(list_of_lists)


def all_equal(iterable):
    g = groupby(iterable)
    return next(g, True) and not next(g, False)


C = [list(map(int, input().split())) for _ in range(3)]
s = sum(flatten(C))

x = all_equal([C[1][i] - C[0][i] for i in range(3)])
y = all_equal([C[2][i] - C[0][i] for i in range(3)])
z = all_equal([C[2][i] - C[1][i] for i in range(3)])

if all((x, y, z)) and s % 3 == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

c = [[int(x) for x in input().split()] for _ in range(3)]

for i in range(101):
    for j in range(101):
        for k in range(101):
            b1, b2, b3 = [x - i for x in c[0]]
            if [b1 + j, b2 + j, b3 + j] == c[1] and [b1 + k, b2 + k, b3 + k] == c[2]:
                print("Yes")
                sys.exit()
print("No")

Submission status: Accepted

Solution code:
C = [list(map(int, input().split())) for i in range(3)]


A1 = [C[0][0] - C[1][0], C[0][1] - C[1][1],C[0][2] - C[1][2]]
A1.sort()
A2 = [C[1][0] - C[2][0], C[1][1] - C[2][1],C[1][2] - C[2][2]]
A2.sort()
B1 = [C[0][0] - C[0][1], C[1][0] - C[1][1],C[2][0] - C[2][1]]
B1.sort()
B2 = [C[0][1] - C[0][2], C[1][1] - C[1][2],C[2][1] - C[2][2]]
B2.sort()
if A1[0] == A1[2] and A2[0] == A2[2] and B1[0] == B1[2] and B2[0] == B2[2]:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    C = [[int(c) for c in input().split()] for _ in range(3)]
    possible = True
    for i in range(3):
        if abs(C[i][0] - C[(i+1) % 3][0]) == abs(C[i][1] - C[(i+1) % 3][1]) == abs(C[i][2] - C[(i+1) % 3][2]): continue
        else:
            print("No")
            break
    else:
        for j in range(3):
            if abs(C[0][j] - C[0][(j+1) % 3]) == abs(C[1][j] - C[1][(j+1) % 3]) == abs(C[2][j] - C[2][(j+1) % 3]): continue
            else:
                print("No")
                break
        else: print("Yes")

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
c = list(list(map(int, input().split())) for _ in range(3))
c00 = c[0][0]
c11 = c[1][1]
c22 = c[2][2]
for a0 in range(c00 + 1):
    for a1 in range(c11 + 1):
        for a2 in range(c22 + 1):
            A = [a0, a1, a2]
            B = [c00 - a0, c11 - a1, c22 - a2]
            tmp = []
            for a in A:
                row = []
                for b in B:
                    row.append(a + b)
                tmp.append(row)
            if tmp == c:
                print('Yes')
                exit()
print('No')

Submission status: Accepted

Solution code:
*C, = map(int, open(0).read().split())

a1 = 0
a2 = C[3]-C[0]
a3 = C[6]-C[0]

b1 = C[0]
b2 = C[1]
b3 = C[2]

A = [a1, a2, a3]
B = [b1, b2, b3]


for i in range(3):
    for j in range(3):
        if C[i*3+j] != A[i]+B[j]:
            print('No')
            exit()

print('Yes')

Submission status: Accepted

Solution code:
C = [list(map(int,input().split())) for _ in range(3)]
if C[0][0]-C[0][1]==C[1][0]-C[1][1]==C[2][0]-C[2][1] and C[0][1]-C[0][2]==C[1][1]-C[1][2]==C[2][1]-C[2][2] \
    and C[1][0]-C[0][0]==C[1][1]-C[0][1]==C[1][2]-C[0][2] and C[2][0]-C[1][0]==C[2][1]-C[1][1]==C[2][2]-C[1][2]:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
c = [list(map(int,input().split())) for _ in range(3)]
#print(LIST)
# a1 = 0 とする
a,b= [0,0,0],[0,0,0]
for i in range(3):
    b[i] = c[0][i] - a[0]
for j in range(1,3):
    a[j] = c[j][0] - b[0]
for i in range(1,3):
    for j in range(1,3):
        #print(a,b)
        if c[j][i] == a[j] + b[i]:
            pass
        else:
            print('No')
            exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
c=list(map(int,input().split()))
diffa=c[1]-c[0]
diffb=c[2]-c[1]

c=list(map(int,input().split()))
if(diffa!=(c[1]-c[0]) or diffb!=(c[2]-c[1])):
    print("No")
    sys.exit()

c=list(map(int,input().split()))
if(diffa!=(c[1]-c[0]) or diffb!=(c[2]-c[1])):
    print("No")
    sys.exit()

print("Yes")

Submission status: Accepted

Solution code:
C = [list(map(int, input().split())) for _ in range(3)]
flag = True
for i in range(2):
    if C[i+1][0]-C[i][0] == C[i+1][1]-C[i][1] and C[i+1][0]-C[i][0] ==  C[i+1][2]-C[i][2]:
        pass
    else:
        flag = False

for i in range(2):
    if C[0][i+1]-C[0][i] == C[1][i+1]-C[1][i] and C[0][i+1]-C[0][i] ==  C[2][i+1]-C[2][i]:
        pass
    else:
        flag = False

if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
c = [list(map(int, input().split())) for _ in range(3)]

ans = "Yes"
for i in range(1,3):
  if c[i][0]-c[0][0] != c[i][1]-c[0][1] or c[i][1]-c[0][1] != c[i][2]-c[0][2]:
    ans = "No"
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

c = [list(map(int, input().split())) for _ in range(3)]
flag = True

for i in range(3):
    if c[i][1]-c[i][0]!=c[0][1]-c[0][0]:
        flag = False

for i in range(3):
    if c[i][2]-c[i][1]!=c[0][2]-c[0][1]:
        flag = False

for i in range(3):
    if c[1][i]-c[0][i]!=c[1][0]-c[0][0]:
        flag = False

for i in range(3):
    if c[2][i]-c[1][i]!=c[2][0]-c[1][0]:
        flag = False

if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# a1 を既知とすると
# c11 = a1 + b1 となり
# b1 = c11 - a1 が定まる
# さらに ci1 = ai + b1 であるから
# a2 = c21 - b1 と
# a3 = c31 - b1 が定まる
# すると b2 =  c12  - a1 と b3  = c13 - a1　も定まる
# よって (a1, a2, a3, b1, b2, b3) = (a1, c21-c11+a1, c31-c11+a1, c11-a1, c12-a1, c13-a1) と定まる
# ここで (a1, a2, a3, b1, b2, b3) = (p1+x, p2+x, p3+x, q1-x, q2-x, q3-x) とおけば
# x を適切に設定する事で a1 = 0 と仮定することができる (aiとbjでxが相殺される)
# 従って (a1, a2, a3, b1, b2, b3) = (0, c21-c11, c31-c11, c11, c12, c13) である

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

a1, a2, a3, b1, b2, b3 = 0, c[1][0]-c[0][0], c[2][0]-c[0][0], c[0][0], c[0][1], c[0][2]

# print("(a1, a2, a3, b1, b2, b3) = ({}, {}, {}, {}, {}, {})".format(a1, a2, a3, b1, b2, b3))

if c[0][0] == a1 + b1 and c[0][1] == a1 + b2 and c[0][2] == a1 + b3 \
    and c[1][0] == a2 + b1 and c[1][1] == a2 + b2 and c[1][2] == a2 + b3 \
    and c[2][0] == a3 + b1 and c[2][1] == a3 + b2 and c[2][2] == a3 + b3:

    print("Yes")

else:

    print("No")

Submission status: Accepted

Solution code:
c11,c12,c13 = map(int,input().split())
c21,c22,c23 = map(int,input().split())
c31,c32,c33 = map(int,input().split())

a = 0
if c13 - c12 == c23 - c22 == c33 - c32:
  if c12 - c11 == c22 - c21 == c32 - c31:
    if c33 - c23 == c32 - c22 == c31 - c21:
      if c23 - c13 == c22 - c12 == c21 - c11:
        print("Yes")
        a = 1
        
if a == 0:
  print("No")

Submission status: Accepted

Solution code:
c = [list(map(int, input().split())) for _ in range(3)]
s1=sum(c[0])
s2=sum(c[1])
s3=sum(c[2])
s4=c[0][0]+c[1][0]+c[2][0]
s5=c[0][1]+c[1][1]+c[2][1]
s6=c[0][2]+c[1][2]+c[2][2]
for x in [s2-s1, s3-s1, s5-s4, s6-s4]:
    if abs(x)%3 != 0:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
C = [list(map(int, input().split())) for i in range(3)]

for a1 in range(-100, 101):
  b = [c - a1 for c in C[0]]
  for a2 in range(-100, 101):
    if b != [c - a2 for c in C[1]]:
      continue
    for a3 in range(-100, 101):
      if b == [c - a3 for c in C[2]]:
        print('Yes')
        quit()

print('No')

Submission status: Accepted

Solution code:
a11,a12,a13=map(int,input().split())
a21,a22,a23=map(int,input().split())
a31,a32,a33=map(int,input().split())

if a22!=a21+a12-a11:
    print('No')
elif a23!=a21+a13-a11:
    print('No')
elif a32!=a31+a12-a11:
    print('No')
elif a33!=a31+a13-a11:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def read():
    C = []
    for i in range(3):
        c1, c2, c3 = map(int, input().strip().split())
        C.append((c1, c2, c3))
    return C,

def solve(C):
    for b0 in range(101):
        for b1 in range(101):
            for b2 in range(101):
                x = C[0][0] - b0
                y = C[0][1] - b1
                z = C[0][2] - b2
                if x != y or y != z:
                    continue
                x = C[1][0] - b0
                y = C[1][1] - b1
                z = C[1][2] - b2
                if x != y or y != z:
                    continue
                x = C[2][0] - b0
                y = C[2][1] - b1
                z = C[2][2] - b2
                if x != y or y != z:
                    continue
                return "Yes"
    return "No"


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
c = [LI() for _ in range(3)]
x,y,z = c[0]
for x2,y2,z2 in c[1:]:
    d = x2-x
    if not y+d==y2 or not z+d==z2:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
c = [list(map(int,input().split())) for i in range(3)]
a = c[0][0]-c[1][0]
b = c[1][0]-c[2][0]
d = c[0][0]-c[2][0]

if (a == c[0][1]-c[1][1]) and (a==c[0][2] - c[1][2]):
  if (b == c[1][1] - c[2][1]) and (b == c[1][2]-c[2][2]):
    if (d == c[0][1]-c[2][1]) and (d == c[0][2]-c[2][2]):
      print('Yes')
      exit()
      
      
print('No')

Submission status: Accepted

Solution code:
c11,c12,c13 = list(map(int,input().split()))
c21,c22,c23 = list(map(int,input().split()))
c31,c32,c33 = list(map(int,input().split()))
a1 = 0
b1 = c11-a1
b2 = c12-a1
b3 = c13-a1
a2 = c21-b1
a3 = c31-b1
if a2+b2==c22 and a3+b2==c32 and a2+b3==c23 and a3+b3==c33:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def main():
    c = [list(map(int, input().split(' '))) for _ in range(3)]
    for i in range(3):
        next_i = (i + 1) % 3
        d = [c[i][j] - c[next_i][j] for j in range(3)]
        if len(set(d)) > 1:
            print('No')
            return
    for j in range(3):
        next_j = (j + 1) % 3
        d = [c[i][j] - c[i][next_j] for i in range(3)]
        if len(set(d)) > 1:
            print('No')
            return
    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
C = [list(map(int,input().split())) for _ in range(3)]
N = 0
for i in range(3):
  N = max(N, max(C[i]))+1
for i in range(N):
  for j in range(N):
    for k in range(N):
      check = 0
      for l in range(3):
        if C[l][0]-i == C[l][1]-j == C[l][2]-k:
          check += 1
      if check == 3:
        print('Yes')
        exit()

print('No')

Submission status: Accepted

Solution code:
C = [list(map(int, input().split())) for _ in range(3)]
def check(C):
    D = [[c[1] - c[0], c[2] - c[1]] for c in C]
    if D[0] == D[1] == D[2]:
        return 0
    else:
        print('No')
        exit()
check(C)
C = [list(c) for c in zip(*C)]
check(C)
print('Yes')

Submission status: Accepted

Solution code:
grid = [list(map(int, input().split())) for _ in range(3)]
B = [x for x in grid[0]]
b = B[0]
A = [grid[i][0] - b for i in range(3)]
res = True
for i, a in enumerate(A):
    for j, b in enumerate(B):
        if grid[i][j] != a + b:
            res = False
            break
    else:
        continue
    break
print('Yes' if res else 'No')

Submission status: Accepted

Solution code:

[(a,b,c),(d,e,f),(g,h,i)]= [map(int, input().split()) for i in range(3)]

if a-b==d-e==g-h and b-c==e-f==h-i:
  print('Yes')
else:
  print('No')