def findmin(): sum = 0 for i in range(3): for j in range(3): sum = sum + abs(s[i][j]-sq[i][j]) #print('sum',sum) return sum def trans(): global sq #print(type(sq)) #print(sq) for i in range(3): for j in range(3): if(i < j): temp = sq[i][j] sq[i][j] = sq[j][i] sq[j][i] = temp #print(sq) return x = list() s = list() for i in range(3): t = input().split() s.append(t) for i in range(3): for j in range(3): s[i][j] = int(s[i][j]) #print(s) sq = [[2,7,6],[9,5,1],[4,3,8]] #print(sq[2][2]) mini = 1000 for i in range(4): if(i == 2): trans() w = findmin() #print(w) if mini > w: mini = w for j in range(3): sq[j].reverse() #print(sq) w = findmin() #print(w) if mini > w: mini = w sq.reverse() #print(sq) print(mini)