from __future__ import print_function try: input = raw_input except: pass m = [] for i in range(3): m.append([ int(x) for x in input().strip().split(' ') ]) def make_square(a,b,c): return [[c-b,c+a+b,c-a],[c-a+b,c,c+a-b],[c+a,c-a-b,c+b]] def rotate_square(s): tmp = s[0][0] s[0][0] = s[2][0] s[2][0] = s[2][2] s[2][2] = s[0][2] s[0][2] = tmp tmp = s[1][0] s[1][0] = s[2][1] s[2][1] = s[1][2] s[1][2] = s[0][1] s[0][1] = tmp return s def flip_horizontally(s): for i in range(3): (s[i][0],s[i][2]) = (s[i][2],s[i][0]) return s def flip_vertically(s): for i in range(3): (s[0][i],s[2][i]) = (s[2][i],s[0][i]) return s def print_square(s): for r in s: print(' '.join([str(x) for x in r])) def square_dist(s,t): return sum([ abs(s[i][j] - t[i][j]) for i in range(3) for j in range(3) ]) s = make_square(1,3,5) mindist = sum([ sum(r) for r in s ]) + 45 for i in range(4): mindist = min(mindist, square_dist(s,m)) flip_horizontally(s) mindist = min(mindist, square_dist(s,m)) flip_vertically(s) mindist = min(mindist, square_dist(s,m)) flip_horizontally(s) mindist = min(mindist, square_dist(s,m)) flip_vertically(s) rotate_square(s) print(mindist)