#include #include #include #include #include using namespace std; int dif(int inpt[3][3], int m[3][3]) { int sum = 0; for(int i=0; i<3; i++) for(int j=0; j<3; j++) { sum =sum+abs(inpt[i][j]-m[i][j]); } return sum; } int main() { int inpt[3][3]; for(int i=0; i<3; i++) for(int j=0; j<3; j++) cin>>inpt[i][j]; int m1[3][3]={{4,9,2},{3,5,7},{8,1,6}}; int m2[3][3]={{2,7,6},{9,5,1},{4,3,8}}; int m3[3][3]={{6,1,8},{7,5,3},{2,9,4}}; int m4[3][3]={{8,3,4},{1,5,9},{6,7,2}}; int m5[3][3]={{8,1,6},{3,5,7},{4,9,2}}; int m6[3][3]={{6,7,2},{1,5,9},{8,3,4}}; int m7[3][3]={{2,9,4},{7,5,3},{6,1,8}}; int m8[3][3]={{4,3,8},{9,5,1},{2,7,6}}; vector diff(8); diff[0]=dif(inpt,m1); diff[1]=dif(inpt,m2); diff[2]=dif(inpt,m3); diff[3]=dif(inpt,m4); diff[4]=dif(inpt,m5); diff[5]=dif(inpt,m6); diff[6]=dif(inpt,m7); diff[7]=dif(inpt,m8); int min = diff[0]; for(int i=1;i<8;i++){ if(diff[i]