func_code_string: #include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0;     char zf = 1;     char ch = getchar();     while (ch !=  -  && !isdigit(ch)) ch = getchar();     if (ch ==  - ) zf = -1, ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x * zf;   }   void write(long long y) {     if (y < 0) putchar( - ), y = -y;     if (y > 9) write(y / 10);     putchar(y % 10 + 48);   }   void writeln(const long long y) {     write(y);     putchar(  n );   }   int i, j, k, m, n, x, y, z, cnt, dx[10010], dy[10010];   struct now {     int t, x, y, p;   } q[1000010];   int h, t;   long long dis[105][12][12][3];   bool vis[105][12][12][3];   void push(now x, long long ds) {     if (x.x == dx[x.t] && x.y == dy[x.t]) x.t++;     if (ds >= dis[x.t][x.x][x.y][x.p]) return;     dis[x.t][x.x][x.y][x.p] = ds;     if (!vis[x.t][x.x][x.y][x.p])       q[++t] = {x.t, x.x, x.y, x.p}, vis[x.t][x.x][x.y][x.p] = 1;   }   int main() {     n = read();     for (register int i = 1; i <= n; i++)       for (register int j = 1; j <= n; j++) {         x = read();         dx[x] = i;         dy[x] = j;       }     memset(dis, 10, sizeof(dis));     long long ans = 1000000000000ll;     for (register int i = 0; i <= 2; i++)       dis[2][dx[1]][dy[1]][i] = 0, vis[2][dx[1]][dy[1]][i] = 1;     t = 3;     q[1] = {2, dx[1], dy[1], 0};     q[2] = {2, dx[1], dy[1], 1};     q[3] = {2, dx[1], dy[1], 2};     while (h < t) {       now u = q[++h];       vis[u.t][u.x][u.y][u.p] = 0;       long long ds = dis[u.t][u.x][u.y][u.p];       if (u.t > n * n) {         ans = min(ans, ds);         continue;       }       long long b1 = ds + 1000000;       if (u.p == 0) {         for (register int i = 1; i <= n; i++) {           push({u.t, i, u.y, u.p}, b1);           push({u.t, u.x, i, u.p}, b1);         }       }       if (u.p == 1) {         for (register int i = -2; i <= 2; i++)           for (register int j = -2; j <= 2; j++)             if (i * j == 2 || i * j == -2) {               int xx = u.x + i, yy = u.y + j;               if (xx < 1 || xx > n || yy < 1 || yy > n) continue;               push({u.t, xx, yy, u.p}, b1);             }       }       if (u.p == 2) {         for (register int i = -n; i <= n; i++)           for (register int j = -1; j <= 1; j += 2) {             int xx = u.x + i, yy = u.y + i * j;             if (xx < 1 || xx > n || yy < 1 || yy > n) continue;             push({u.t, xx, yy, u.p}, b1);           }       }       for (register int i = 0; i <= 2; i++) push({u.t, u.x, u.y, i}, b1 + 1);     }     cout << ans / 1000000 <<     << ans % 1000000;     return 0;   }   