#include using namespace std; typedef unsigned int UINT32; UINT32 gA[8][3][3] ={ {{4, 9, 2}, {3, 5, 7}, {8, 1, 6} }, {{8, 3, 4}, {1, 5, 9}, {6, 7, 2} }, {{2, 7, 6}, {9, 5, 1}, {4, 3, 8} }, {{6, 7, 2}, {1, 5, 9}, {8, 3, 4} }, {{2, 9, 4}, {7, 5, 3}, {6, 1, 8} }, {{4, 3, 8}, {9, 5, 1}, {2, 7, 6} }, {{6, 1, 8}, {7, 5, 3}, {2, 9, 4} }, {{8, 1, 6}, {3, 5, 7}, {4, 9, 2} } }; UINT32 a[3][3]; int main(void) { UINT32 i, j, k, nTmp, n, nMin = 100; n = 3; for(i = 0; i < n; i++) for(j = 0; j < n; j++) cin >> a[i][j]; for(k = 0; k < 8; k++) { nTmp = 0; for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { if(gA[k][i][j] > a[i][j]) { nTmp += gA[k][i][j] - a[i][j]; } else { nTmp += a[i][j] - gA[k][i][j]; } } } if(nMin > nTmp) nMin = nTmp; } cout << nMin; return 0; }