import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int [][]inputSquare = new int [3][3]; for (int i=0;i<3;i++){ for (int j=0;j<3;j++){ inputSquare[i][j]=scanner.nextInt(); } } int [][]square1={{8,1,6},{3,5,7},{4,9,2}}; int [][]square2={{6,1,8},{7,5,3},{2,9,4}}; int [][]square3={{8,3,4},{1,5,9},{6,7,2}}; int [][]square4={{6,7,2},{1,5,9},{8,3,4}}; int [][]square5={{4,9,2},{3,5,7},{8,1,6}}; int [][]square6={{2,9,4},{7,5,3},{6,1,8}}; int [][]square7={{2,7,6},{9,5,1},{4,3,8}}; int [][]square8={{4,3,8},{9,5,1},{2,7,6}}; int []diff=new int [8]; for (int i=0;i<3;i++){ for (int j=0;j<3;j++){ diff[0]+=Math.abs(square1[i][j]-inputSquare[i][j]); diff[1]+=Math.abs(square2[i][j]-inputSquare[i][j]); diff[2]+=Math.abs(square3[i][j]-inputSquare[i][j]); diff[3]+=Math.abs(square4[i][j]-inputSquare[i][j]); diff[4]+=Math.abs(square5[i][j]-inputSquare[i][j]); diff[5]+=Math.abs(square6[i][j]-inputSquare[i][j]); diff[6]+=Math.abs(square7[i][j]-inputSquare[i][j]); diff[7]+=Math.abs(square8[i][j]-inputSquare[i][j]); } } int min=diff[0]; for (int i=1;i<8;i++){ if(diff[i]