#include #include #include #include using namespace std; int main(int argc, char const *argv[]) { ios::sync_with_stdio(0); int square[3][3]; int sCompare[8][3][3]; sCompare[0][0][0] = 6; sCompare[0][0][1] = 1; sCompare[0][0][2] = 8; sCompare[0][1][0] = 7; sCompare[0][1][1] = 5; sCompare[0][1][2] = 3; sCompare[0][2][0] = 2; sCompare[0][2][1] = 9; sCompare[0][2][2] = 4; sCompare[1][0][0] = 8; sCompare[1][0][1] = 3; sCompare[1][0][2] = 4; sCompare[1][1][0] = 1; sCompare[1][1][1] = 5; sCompare[1][1][2] = 9; sCompare[1][2][0] = 6; sCompare[1][2][1] = 7; sCompare[1][2][2] = 2; sCompare[2][0][0] = 4; sCompare[2][0][1] = 9; sCompare[2][0][2] = 2; sCompare[2][1][0] = 3; sCompare[2][1][1] = 5; sCompare[2][1][2] = 7; sCompare[2][2][0] = 8; sCompare[2][2][1] = 1; sCompare[2][2][2] = 6; sCompare[3][0][0] = 2; sCompare[3][0][1] = 7; sCompare[3][0][2] = 6; sCompare[3][1][0] = 9; sCompare[3][1][1] = 5; sCompare[3][1][2] = 1; sCompare[3][2][0] = 4; sCompare[3][2][1] = 3; sCompare[3][2][2] = 8; sCompare[4][0][0] = 2; sCompare[4][0][1] = 9; sCompare[4][0][2] = 4; sCompare[4][1][0] = 7; sCompare[4][1][1] = 5; sCompare[4][1][2] = 3; sCompare[4][2][0] = 6; sCompare[4][2][1] = 1; sCompare[4][2][2] = 8; sCompare[5][0][0] = 4; sCompare[5][0][1] = 3; sCompare[5][0][2] = 8; sCompare[5][1][0] = 9; sCompare[5][1][1] = 5; sCompare[5][1][2] = 1; sCompare[5][2][0] = 2; sCompare[5][2][1] = 7; sCompare[5][2][2] = 6; sCompare[6][0][0] = 8; sCompare[6][0][1] = 1; sCompare[6][0][2] = 6; sCompare[6][1][0] = 3; sCompare[6][1][1] = 5; sCompare[6][1][2] = 7; sCompare[6][2][0] = 4; sCompare[6][2][1] = 9; sCompare[6][2][2] = 2; sCompare[7][0][0] = 6; sCompare[7][0][1] = 7; sCompare[7][0][2] = 2; sCompare[7][1][0] = 1; sCompare[7][1][1] = 5; sCompare[7][1][2] = 9; sCompare[7][2][0] = 8; sCompare[7][2][1] = 3; sCompare[7][2][2] = 4; for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) cin >> square[i][j]; int total = 100; int cur = 0; for (int i = 0; i < 8; ++i) { cur += abs(sCompare[i][0][0] - square[0][0]); cur += abs(sCompare[i][0][1] - square[0][1]); cur += abs(sCompare[i][0][2] - square[0][2]); cur += abs(sCompare[i][1][0] - square[1][0]); cur += abs(sCompare[i][1][1] - square[1][1]); cur += abs(sCompare[i][1][2] - square[1][2]); cur += abs(sCompare[i][2][0] - square[2][0]); cur += abs(sCompare[i][2][1] - square[2][1]); cur += abs(sCompare[i][2][2] - square[2][2]); if (total > cur) total = cur; cur = 0; } cout << total << '\n'; return 0; }