#include #include using namespace std; int main() { int arr[3][3],i,j; int comb1[3][3]={8,1,6,3,5,7,4,9,2}; int comb2[3][3]={6,1,8,7,5,3,2,9,4}; int comb3[3][3]={4,9,2,3,5,7,8,1,6}; int comb4[3][3]={2,9,4,7,5,3,6,1,8}; int comb5[3][3]={8,3,4,1,5,9,6,7,2}; int comb6[3][3]={4,3,8,9,5,1,2,7,6}; int comb7[3][3]={6,7,2,1,5,9,8,3,4}; int comb8[3][3]={2,7,6,9,5,1,4,3,8}; int cost[8],z; for(i=0;i<8;i++) { cost[i]=0; } for(i=0;i<3;i++) { for(j=0;j<3;j++) { cin>>arr[i][j]; } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { if(arr[i][j]!=comb1[i][j]) { cost[0]+=abs(arr[i][j]-comb1[i][j]); } if(arr[i][j]!=comb2[i][j]) { cost[1]+=abs(arr[i][j]-comb2[i][j]); } if(arr[i][j]!=comb3[i][j]) { cost[2]+=abs(arr[i][j]-comb3[i][j]); } if(arr[i][j]!=comb4[i][j]) { cost[3]+=abs(arr[i][j]-comb4[i][j]); } if(arr[i][j]!=comb5[i][j]) { cost[4]+=abs(arr[i][j]-comb5[i][j]); } if(arr[i][j]!=comb6[i][j]) { cost[5]+=abs(arr[i][j]-comb6[i][j]); } if(arr[i][j]!=comb7[i][j]) { cost[6]+=abs(arr[i][j]-comb7[i][j]); } if(arr[i][j]!=comb8[i][j]) { cost[7]+=abs(arr[i][j]-comb8[i][j]); } } } int min=0; min=cost[0]; for(i=1;i<8;i++) { if(cost[i]