#include #include #include #include int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int a[3][3],i,j; int square1[3][3]={{8,1,6},{3,5,7},{4,9,2}}; int square2[3][3]={{6,1,8},{7,5,3},{2,9,4}}; int square3[3][3]={{4,9,2},{3,5,7},{8,1,6}}; int square4[3][3]={{2,9,4},{7,5,3},{6,1,8}}; int square5[3][3]={{8,3,4},{1,5,9},{6,7,2}}; int square6[3][3]={{4,3,8},{9,5,1},{2,7,6}}; int square7[3][3]={{6,7,2},{1,5,9},{8,3,4}}; int square8[3][3]={{2,7,6},{9,5,1},{4,3,8}}; for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } int sum[8]={0}; for(i=0;i<3;i++) { for(j=0;j<3;j++) { sum[0]+=abs(a[i][j]-square1[i][j]); sum[1]+=abs(a[i][j]-square2[i][j]); sum[2]+=abs(a[i][j]-square3[i][j]); sum[3]+=abs(a[i][j]-square4[i][j]); sum[4]+=abs(a[i][j]-square5[i][j]); sum[5]+=abs(a[i][j]-square6[i][j]); sum[6]+=abs(a[i][j]-square7[i][j]); sum[7]+=abs(a[i][j]-square8[i][j]); } } int largest=abs(sum[0]); for(i=1;i<8;i++) { sum[i]=abs(sum[i]); if(largest>sum[i]) largest=sum[i]; } printf("%d",abs(largest)); return 0; }