#include #include using namespace std; int count; void check(int A[][3], int X[][3]) { int c=0; for(int i=0; i<3; ++i) for(int j=0; j<3; ++j) { c+=abs(A[i][j]-X[i][j]); } if(c < count) count = c; } int main() { int A1[3][3] = {{8,1,6},{3,5,7},{4,9,2}}; int A2[3][3] = {{6,1,8},{7,5,3},{2,9,4}}; int A3[3][3] = {{4,9,2},{3,5,7},{8,1,6}}; int A4[3][3] = {{2,9,4},{7,5,3},{6,1,8}}; int A5[3][3] = {{8,3,4},{1,5,9},{6,7,2}}; int A6[3][3] = {{4,3,8},{9,5,1},{2,7,6}}; int A7[3][3] = {{6,7,2},{1,5,9},{8,3,4}}; int A8[3][3] = {{2,7,6},{9,5,1},{4,3,8}}; int A[3][3]; for(int i=0; i<3; ++i) for(int j=0; j<3; ++j) cin >> A[i][j]; count = 1000; check(A, A1);check(A, A2);check(A, A3);check(A, A4); check(A, A5);check(A, A6);check(A, A7);check(A, A8); cout << count; return 0; }