import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static int compare(int ar[][],int br[][]){ int i,j;int sum=0; int z; for(i=0;i<3;i++){ for(j=0;j<3;j++){ z=ar[i][j]-br[i][j]; if(z>0) sum=sum+z; else sum=sum-z; } } return sum; } public static void main(String[] args) { int i,j; int a[][]={{8,1,6},{3,5,7},{4,9,2}}; int b[][]={{6,1,8},{7,5,3},{2,9,4}}; int c[][]={{4,3,8},{9,5,1},{2,7,6}}; int d[][]={{2,7,6},{9,5,1},{4,3,8}}; int e[][]={{2,9,4},{7,5,3},{6,1,8}}; int f[][]={{4,9,2},{3,5,7},{8,1,6}}; int g[][]={{6,7,2},{1,5,9},{8,3,4}}; int h[][]={{8,3,4},{1,5,9},{6,7,2}}; int[] maxi=new int[9]; // int mxm=0; Scanner in = new Scanner(System.in); int[][] x=new int[3][3]; for(i=0;i<3;i++) { for(j=0;j<3;j++) { x[i][j]=in.nextInt(); } } maxi[0]=compare(x,a); maxi[1]=compare(x,b); maxi[2]=compare(x,c); maxi[3]=compare(x,d); maxi[4]=compare(x,e); maxi[5]=compare(x,f); maxi[6]=compare(x,g); maxi[7]=compare(x,h); int least=maxi[0]; for(i=1;i<8;i++){ if(least>maxi[i]){ least=maxi[i]; } } System.out.print(least); } }