using System; using System.Collections.Generic; using System.IO; class Solution { static void Main(String[] args) { string row1 = Console.ReadLine().Replace(" ", ""); string row2 = Console.ReadLine().Replace(" ", ""); string row3 = Console.ReadLine().Replace(" ", ""); int[,] matrix = new int[3, 3]; string currentRow = null; for(int i = 0; i < 3; i++) { if(currentRow == null) { currentRow = row1; } else if(currentRow == row1) { currentRow = row2; } else { currentRow = row3; } for (int j = 0; j < 3; j++) { matrix[i,j] = int.Parse(currentRow[j].ToString()); } } int test1 = matrix[0,0] + matrix[0,1] + matrix[0,2]; int test2 = matrix[0,0] + matrix[1,0] + matrix[2,0]; int test3 = matrix[2,0] + matrix[2,1] + matrix[2,2]; int test4 = matrix[2,2] + matrix[1,2] + matrix[0,2]; int test5 = matrix[0,1] + matrix[1,1] + matrix[2,1]; int test6 = matrix[1,0] + matrix[1,1] + matrix[1,2]; int test7 = matrix[0,0] + matrix[1,1] + matrix[2,2]; int test8 = matrix[2,0] + matrix[1,1] + matrix[0,2]; int smallest = 999; if(test1 != 15) { int cost = Math.Abs(test1 - 15); if(cost < smallest) { smallest = cost; } } if(test2 != 15) { int cost = Math.Abs(test2 - 15); if(cost < smallest) { smallest = cost; } } if(test3 != 15) { int cost = Math.Abs(test3 - 15); if(cost < smallest) { smallest = cost; } } if(test4 != 15) { int cost = Math.Abs(test4 - 15); if(cost < smallest) { smallest = cost; } } if(test5 != 15) { int cost = Math.Abs(test5 - 15); if(cost < smallest) { smallest = cost; } } if(test6 != 15) { int cost = Math.Abs(test6 - 15); if(cost < smallest) { smallest = cost; } } if(test7 != 15) { int cost = Math.Abs(test7 - 15); if(cost < smallest) { smallest = cost; } } if(test8 != 15) { int cost = Math.Abs(test8 - 15); if(cost < smallest) { smallest = cost; } } Console.WriteLine(smallest); } }