#include #include #include #include #include using namespace std; const int MagicSquare[][9] = { {4,9,2, 3,5,7, 8,1,6}, {8,3,4, 1,5,9, 6,7,2}, {6,1,8, 7,5,3, 2,9,4}, {2,7,6, 9,5,1, 4,3,8}, {4,3,8, 9,5,1, 2,7,6}, {8,1,6, 3,5,7, 4,9,2}, {6,7,2, 1,5,9, 8,3,4}, {2,9,4, 7,5,3, 6,1,8} }; const int maxn = 9; int arr[maxn]; int swth[maxn]; int main() { while (scanf("%d", &arr[0]) != EOF) { for (int i = 1; i < maxn; ++i) { scanf("%d", &arr[i]); } int minn = 0x7fffffff; for (int i = 0; i < 8; ++i) { int total = 0; for (int j = 0; j < maxn; ++j) { int delta = MagicSquare[i][j] - arr[j]; total += abs(delta); } minn = min(total,minn); } printf("%d\n", minn); } return 0; }