# Enter your code here. Read input from STDIN. Print output to STDOUT import sys import sys AllMats = [([8,1,6],[3,5,7],[4,9,2]),([6,1,8],[7,5,3],[2,9,4]),([4,9,2],[3,5,7],[8,1,6]),([2,9,4],[7,5,3],[6,1,8]),([8,3,4],[1,5,9],[7,6,2]),([4,3,8],[9,5,1],[2,7,6]),([6,7,2],[1,5,9],[8,3,4]),([2,7,6],[9,5,1],[4,3,8])] #row1 = map(int,raw_input().strip().split(' ')) #row2 = map(int,raw_input().strip().split(' ')) #row3 = map(int,raw_input().strip().split(' ')) matIn = [] matIn.append(map(int,raw_input().strip().split(' '))) matIn.append(map(int,raw_input().strip().split(' '))) matIn.append(map(int,raw_input().strip().split(' '))) diff = 1000 ind = 10 for i,mat in enumerate(AllMats): diffT = 0 for j in range(3): for k in range(3): diffT = diffT + abs((mat[j][k]) - (matIn[j][k])) #print i, diff #print "\n" if diffT < diff: diff =diffT ind = i #chosenMat = AllMats[ind] print diff