func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 12;   const int M = 305;   const int INF = 1e9;   int n;   int a[N][N];   pair<int, int> pos[N * N];   pair<int, int> dist[M][M];   pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {     return make_pair(a.first + b.first, a.second + b.second);   }   int dx[] = {-2, -1, 1, 2, 2, 1, -1, -2};   int dy[] = {1, 2, 2, 1, -1, -2, -2, -1};   bool in(int first, int second) {     return (0 <= first && first < n && 0 <= second && second < n);   }   int get(int first, int second, int p) { return first * n * 3 + second * 3 + p; }   pair<int, int> dp[N * N][3];   int main() {     scanf( %d , &n);     for (int i = 0; i < int(n); i++)       for (int j = 0; j < int(n); j++) {         scanf( %d , &a[i][j]);         --a[i][j];         pos[a[i][j]] = make_pair(i, j);       }     for (int i = 0; i < int(M); i++)       for (int j = 0; j < int(M); j++) dist[i][j] = make_pair(INF, INF);     for (int i = 0; i < int(M); i++) dist[i][i] = make_pair(0, 0);     for (int first = 0; first < int(n); first++)       for (int second = 0; second < int(n); second++) {         for (int i = 0; i < int(8); i++) {           int nx = first + dx[i];           int ny = second + dy[i];           if (in(nx, ny))             dist[get(first, second, 0)][get(nx, ny, 0)] = make_pair(1, 0);         }         for (int i = -n + 1; i <= n - 1; ++i) {           int nx = first + i;           int ny = second + i;           if (in(nx, ny))             dist[get(first, second, 1)][get(nx, ny, 1)] = make_pair(1, 0);           ny = second - i;           if (in(nx, ny))             dist[get(first, second, 1)][get(nx, ny, 1)] = make_pair(1, 0);         }         for (int i = 0; i < int(n); i++) {           int nx = first;           int ny = i;           dist[get(first, second, 2)][get(nx, ny, 2)] = make_pair(1, 0);           nx = i;           ny = second;           dist[get(first, second, 2)][get(nx, ny, 2)] = make_pair(1, 0);         }         for (int i = 0; i < int(3); i++)           for (int j = 0; j < int(3); j++) {             if (i != j) {               dist[get(first, second, i)][get(first, second, j)] =                   make_pair(1, 1);             }           }       }     for (int k = 0; k < int(M); k++)       for (int i = 0; i < int(M); i++)         for (int j = 0; j < int(M); j++)           dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);     for (int i = 0; i < int(N * N); i++)       for (int j = 0; j < int(3); j++) dp[i][j] = make_pair(INF, INF);     dp[0][0] = dp[0][1] = dp[0][2] = make_pair(0, 0);     for (int i = 0; i < int(n * n - 1); i++)       for (int j = 0; j < int(3); j++)         for (int k = 0; k < int(3); k++)           dp[i + 1][k] =               min(dp[i + 1][k],                   dp[i][j] + dist[get(pos[i].first, pos[i].second, j)]                                  [get(pos[i + 1].first, pos[i + 1].second, k)]);     pair<int, int> ans = make_pair(INF, INF);     ans = min(ans, dp[n * n - 1][0]);     ans = min(ans, dp[n * n - 1][1]);     ans = min(ans, dp[n * n - 1][2]);     printf( %d %d n , ans.first, ans.second);     return 0;   }   