import java.util.Scanner; public class MagicSquares { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int arr[][] = new int[3][3]; int count[] = new int[8]; int m1[][] = {{8,1,6},{3,5,7},{4,9,2}}; int m2[][] = {{6,1,8},{7,5,3},{2,9,4}}; int m3[][] = {{4,9,2},{3,5,7},{8,1,6}}; int m4[][] = {{2,9,4},{7,5,3},{6,1,8}}; int m5[][] = {{8,3,4},{1,5,9},{6,7,2}}; int m6[][] = {{4,3,8},{9,5,1},{2,7,6}}; int m7[][] = {{6,7,2},{1,5,9},{8,3,4}}; int m8[][] = {{2,7,6},{9,5,1},{4,3,8}}; int smallest; /*for(int i = 0;i<8;i++){ System.out.println(count[i]); }*/ Scanner sc = new Scanner(System.in); for(int i = 0;i<3;i++){ for(int j = 0;j<3;j++){ arr[i][j] = sc.nextInt(); count[0] += Math.abs(arr[i][j]-m1[i][j]); count[2] += Math.abs(arr[i][j]-m3[i][j]); count[3] += Math.abs(arr[i][j]-m4[i][j]); count[4] += Math.abs(arr[i][j]-m5[i][j]); count[5] += Math.abs(arr[i][j]-m6[i][j]); count[6] += Math.abs(arr[i][j]-m7[i][j]); count[7] += Math.abs(arr[i][j]-m8[i][j]); count[1] += Math.abs(arr[i][j]-m2[i][j]); } /*for(int k= 0;k<8;k++){ System.out.println(count[k]); }*/ } smallest = count[0]; for(int i = 1;i<8;i++){ if(count[i]