#include #define ll long long int #define gt(i) scanf("%lld", &i) using namespace std; int main() { ll i, j, k, n, m; ll mt[8][3][3] = {{{4, 9, 2}, {3, 5, 7}, {8, 1, 6}}, {{4, 3, 8}, {9, 5, 1}, {2, 7, 6}}, {{8, 1, 6}, {3, 5, 7}, {4, 9, 2}}, {{8, 3, 4}, {1, 5, 9}, {6, 7, 2}}, {{6, 1, 8}, {7, 5, 3}, {2, 9, 4}}, {{6, 7, 2}, {1, 5, 9}, {8, 3, 4}}, {{2, 7, 6}, {9, 5, 1}, {4, 3, 8}}, {{2, 9, 4}, {7, 5, 3}, {6, 1, 8}}}; ll ans[3][3]; for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { gt(ans[i][j]); } } ll minv = INT_MAX, diff; for(i = 0; i < 8; i++) { diff = 0; for(j = 0; j < 3; j++) { for(k = 0; k < 3; k++) { diff += abs(mt[i][j][k] - ans[j][k]); } } if(diff < minv) minv = diff; } cout << minv << endl; return 0; }