sqr1 = [[8,1,6],[3,5,7],[4,9,2]] sqr11 = [[4,9,2],[3,5,7],[8,1,6]] sqr2 = [[4,3,8],[9,5,1],[2,7,6]] sqr22 = [[2,7,6],[9,5,1],[4,3,8]] sqr3 = [[2,9,4],[7,5,3],[6,1,8]] sqr33 = [[6,1,8],[7,5,3],[2,9,4]] sqr4 = [[6,7,2],[1,5,9],[8,3,4]] sqr44 = [[8,3,4],[1,5,9],[6,7,2]] sqrs = [sqr1]+[sqr2]+[sqr3]+[sqr4]+[sqr11]+[sqr22]+[sqr33]+[sqr44] line1 = map(int, raw_input().split()) line2 = map(int, raw_input().split()) line3 = map(int, raw_input().split()) ##mat = [[4, 9, 2], [3, 5, 7], [8, 1, 5]] mat = [line1]+[line2]+[line3] def pprint(mat): for row in range(3): for col in range(2): print mat[row][col], print mat[row][2] def diff(mat): bestdff = 100000 bestmat = [] for sqr in sqrs: dff = 0 for row in range(3): for col in range(3): dff += abs(mat[row][col]-sqr[row][col]) if dff < bestdff: bestdff = dff bestmat = sqr return(bestdff, bestmat) print(diff(mat)[0])