using System; using System.Collections.Generic; using System.IO; class Solution { static int[][] squares; static void Main(String[] args) { string tempSquare = Console.ReadLine(); for(int i = 1; i < 3; i++){ tempSquare = tempSquare + ' ' + Console.ReadLine(); } int[] square = Array.ConvertAll(tempSquare.Split(' '), Int32.Parse); GenerateSquares(); CompareSquares(square); } static void GenerateSquares(){ squares = new int[8][]; for(int i = 0; i < 8; i ++){ squares[i] = new int[9]; } squares[0] = new int[] {8,1,6,3,5,7,4,9,2}; squares[1] = new int[] {4,3,8,9,5,1,2,7,6}; squares[2] = new int[] {2,9,4,7,5,3,6,1,8}; squares[3] = new int[] {6,7,2,1,5,9,8,3,4}; squares[4] = new int[] {6,1,8,7,5,3,2,9,4}; squares[5] = new int[] {4,9,2,3,5,7,8,1,6}; squares[6] = new int[] {8,3,4,1,5,9,6,7,2}; squares[7] = new int[] {2,7,6,9,5,1,4,3,8}; } static void CompareSquares(int[] square){ int currentDiff; int minDiff = 1000; for(int i = 0; i < 8; i ++){ currentDiff = 0; for(int number = 0; number < 9; number ++){ currentDiff += Math.Abs(square[number] - squares[i][number]); } if (currentDiff < minDiff){ minDiff = currentDiff; } } Console.WriteLine(minDiff); } }