using System; using System.Collections.Generic; using System.IO; class Solution { static void Main(String[] args) { int[] digits = new int[9]; int[][] squares = new int[][] { new int[] {6, 1, 8, 7, 5, 3, 2, 9, 4}, new int[] {8, 1, 6, 3, 5, 7, 4, 9, 2}, new int[] {8, 3, 4, 1, 5, 9, 6, 7, 2}, new int[] {6, 7, 2, 1, 5, 9, 8, 3, 4}, new int[] {2, 7, 6, 9, 5, 1, 4, 3, 8}, new int[] {4, 3, 8, 9, 5, 1, 2, 7, 6}, new int[] {4, 9, 2, 3, 5, 7, 8, 1, 6}, new int[] {2, 9, 4, 7, 5, 3, 6, 1, 8} }; int k = 0; for (int i = 0; i < 3; i++){ int[] n1 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); for (int j = 0; j < 3; j++, k++){ digits[k]=(n1[j]); } } int minchange = 100; for (int i1 = 0; i1 < 8; i1++){ int change = 0; for (int i2 = 0; i2 < 9; i2++){ change+= (digits[i2] - squares[i1][i2] > 0 ? (digits[i2] - squares[i1][i2]) : (squares[i1][i2]-digits[i2])); } if (minchange > change) minchange = change; } Console.WriteLine(minchange); } }