#include #include #include #include int main() { int digits[9]; int squares[8][9] = { {6, 1, 8, 7, 5, 3, 2, 9, 4}, {8, 1, 6, 3, 5, 7, 4, 9, 2}, {8, 3, 4, 1, 5, 9, 6, 7, 2}, {6, 7, 2, 1, 5, 9, 8, 3, 4}, {2, 7, 6, 9, 5, 1, 4, 3, 8}, {4, 3, 8, 9, 5, 1, 2, 7, 6}, {4, 9, 2, 3, 5, 7, 8, 1, 6}, {2, 9, 4, 7, 5, 3, 6, 1, 8} }; for (int i = 0; i < 9; i++){ scanf("%i", &digits[i]); } int minchange = 100; for (int i1 = 0; i1 < 8; i1++){ int change = 0; for (int i2 = 0; i2 < 9; i2++){ if (digits[i2] < squares[i1][i2]) change += squares[i1][i2] - digits[i2]; else if (digits[i2] > squares[i1][i2]) change += digits[i2] - squares[i1][i2]; } if (minchange > change) minchange = change; } printf("%i", minchange); return 0; }