#include #include #include #include int main() { int arr[3][3]; int ourarr1[3][3]={2,7,6,9,5,1,4,3,8}; int ourarr2[3][3]={4,9,2,3,5,7,8,1,6}; int ourarr3[3][3]={8,3,4,1,5,9,6,7,2}; int ourarr4[3][3]={6,1,8,7,5,3,2,9,4}; int ourarr5[3][3]={6,7,2,1,5,9,8,3,4}; int ourarr6[3][3]={8,1,6,3,5,7,4,9,2}; int ourarr7[3][3]={4,3,8,9,5,1,2,7,6}; int ourarr8[3][3]={2,9,4,7,5,3,6,1,8}; unsigned int cost=0, newcost=0; for(int row=0;row<3;row++){ for(int col=0;col<3;col++){ scanf("%d",&arr[row][col]); } } for(int a1=0;a1<3;a1++){ for(int b1=0;b1<3;b1++){ if(arr[a1][b1]>=ourarr1[a1][b1]) newcost=newcost+(arr[a1][b1]-ourarr1[a1][b1]); else newcost=newcost+(ourarr1[a1][b1]-arr[a1][b1]); } } cost=newcost; newcost=0; for(int a1=0;a1<3;a1++){ for(int b1=0;b1<3;b1++){ if(arr[a1][b1]>=ourarr2[a1][b1]) newcost=newcost+(arr[a1][b1]-ourarr2[a1][b1]); else newcost=newcost+(ourarr2[a1][b1]-arr[a1][b1]); } } if(cost>newcost) cost=newcost; else cost=cost; newcost=0; for(int a1=0;a1<3;a1++){ for(int b1=0;b1<3;b1++){ if(arr[a1][b1]>=ourarr3[a1][b1]) newcost=newcost+(arr[a1][b1]-ourarr3[a1][b1]); else newcost=newcost+(ourarr3[a1][b1]-arr[a1][b1]); } } if(cost>newcost) cost=newcost; else cost=cost; newcost=0; for(int a1=0;a1<3;a1++){ for(int b1=0;b1<3;b1++){ if(arr[a1][b1]>=ourarr4[a1][b1]) newcost=newcost+(arr[a1][b1]-ourarr4[a1][b1]); else newcost=newcost+(ourarr4[a1][b1]-arr[a1][b1]); } } if(cost>newcost) cost=newcost; else cost=cost; newcost=0; for(int a1=0;a1<3;a1++){ for(int b1=0;b1<3;b1++){ if(arr[a1][b1]>=ourarr5[a1][b1]) newcost=newcost+(arr[a1][b1]-ourarr5[a1][b1]); else newcost=newcost+(ourarr5[a1][b1]-arr[a1][b1]); } } if(cost>newcost) cost=newcost; else cost=cost; newcost=0; for(int a1=0;a1<3;a1++){ for(int b1=0;b1<3;b1++){ if(arr[a1][b1]>=ourarr6[a1][b1]) newcost=newcost+(arr[a1][b1]-ourarr6[a1][b1]); else newcost=newcost+(ourarr6[a1][b1]-arr[a1][b1]); } } if(cost>newcost) cost=newcost; else cost=cost; newcost=0; for(int a1=0;a1<3;a1++){ for(int b1=0;b1<3;b1++){ if(arr[a1][b1]>=ourarr7[a1][b1]) newcost=newcost+(arr[a1][b1]-ourarr7[a1][b1]); else newcost=newcost+(ourarr7[a1][b1]-arr[a1][b1]); } } if(cost>newcost) cost=newcost; else cost=cost; newcost=0; for(int a1=0;a1<3;a1++){ for(int b1=0;b1<3;b1++){ if(arr[a1][b1]>=ourarr8[a1][b1]) newcost=newcost+(arr[a1][b1]-ourarr8[a1][b1]); else newcost=newcost+(ourarr8[a1][b1]-arr[a1][b1]); } } if(cost>newcost) cost=newcost; else cost=cost; newcost=0; printf("%d",cost); }