#include #include #include #include #include using namespace std; int main() { int ms[3][3]; //vector msq(8); int msq[8][3][3]; msq[0][0][0] = 4; msq[0][0][1] = 9; msq[0][0][2] = 2; msq[0][1][0] = 3; msq[0][1][1] = 5; msq[0][1][2] = 7; msq[0][2][0] = 8; msq[0][2][1] = 1; msq[0][2][2] = 6; msq[1][0][0] = 6; msq[1][0][1] = 1; msq[1][0][2] = 8; msq[1][1][0] = 7; msq[1][1][1] = 5; msq[1][1][2] = 3; msq[1][2][0] = 2; msq[1][2][1] = 9; msq[1][2][2] = 4; msq[2][0][0] = 8; msq[2][0][1] = 3; msq[2][0][2] = 4; msq[2][1][0] = 1; msq[2][1][1] = 5; msq[2][1][2] = 9; msq[2][2][0] = 6; msq[2][2][1] = 7; msq[2][2][2] = 2; msq[3][0][0] = 4; msq[3][0][1] = 3; msq[3][0][2] = 8; msq[3][1][0] = 9; msq[3][1][1] = 5; msq[3][1][2] = 1; msq[3][2][0] = 2; msq[3][2][1] = 7; msq[3][2][2] = 6; msq[4][0][0] = 2; msq[4][0][1] = 9; msq[4][0][2] = 4; msq[4][1][0] = 7; msq[4][1][1] = 5; msq[4][1][2] = 3; msq[4][2][0] = 6; msq[4][2][1] = 1; msq[4][2][2] = 8; msq[5][0][0] = 6; msq[5][0][1] = 7; msq[5][0][2] = 2; msq[5][1][0] = 1; msq[5][1][1] = 5; msq[5][1][2] = 9; msq[5][2][0] = 8; msq[5][2][1] = 3; msq[5][2][2] = 4; msq[6][0][0] = 8; msq[6][0][1] = 1; msq[6][0][2] = 6; msq[6][1][0] = 3; msq[6][1][1] = 5; msq[6][1][2] = 7; msq[6][2][0] = 4; msq[6][2][1] = 9; msq[6][2][2] = 2; msq[7][0][0] = 2; msq[7][0][1] = 7; msq[7][0][2] = 6; msq[7][1][0] = 9; msq[7][1][1] = 5; msq[7][1][2] = 1; msq[7][2][0] = 4; msq[7][2][1] = 3; msq[7][2][2] = 8; int cost = 100; cin >> ms[0][0] >> ms[0][1] >> ms[0][2]; cin >> ms[1][0] >> ms[1][1] >> ms[1][2]; cin >> ms[2][0] >> ms[2][1] >> ms[2][2]; for(int i = 0; i < 8; i++){ int totalCost = 0; for(int c = 0; c < 3; c ++){ for(int t = 0; t < 3; t ++){ totalCost += fabs(msq[i][c][t] - ms[c][t]); } } if(cost > totalCost){ cost = totalCost; } } cout << cost; return 0; }