# Enter your code here. Read input from STDIN. Print output to STDOUT square = [] for _ in range(3): square.append([int(num) for num in raw_input().split()]) # square.reverse() solutions = [] solutions.append([[4, 9, 2], [3, 5, 7], [8, 1, 6]]) solutions.append([[8, 1, 6], [3, 5, 7], [4, 9, 2]]) solutions.append([[2, 9, 4], [7, 5, 3], [6, 1, 8]]) solutions.append([[6, 1, 8], [7, 5, 3], [2, 9, 4]]) solutions.append([[2, 7, 6], [9, 5, 1], [4, 3, 8]]) solutions.append([[4, 3, 8], [9, 5, 1], [2, 7, 6]]) solutions.append([[6, 7, 2], [1, 5, 9], [8, 3, 4]]) solutions.append([[8, 3, 4], [1, 5, 9], [6, 7, 2]]) min_diff = 1000 for solution in solutions: diff = 0 for row in range(3): for column in range(3): diff += abs(solution[row][column] - square[row][column]) if diff < min_diff: min_diff = diff print min_diff