#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 (ds >= dis[x.t][x.x][x.y][x.p]) return;
  dis[x.t][x.x][x.y][x.p] = ds;
  q[++t] = {x.t, x.x, x.y, x.p};
}
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 a1 = ds, b1 = ds;
    a1 += 1000001;
    b1 += 1000000;
    if (u.p == 0) {
      for (register int i = 1; i <= n; i++) {
        if (i == dx[u.t] && u.y == dy[u.t])
          push({u.t + 1, i, u.y, u.p}, b1);
        else
          push({u.t, i, u.y, u.p}, b1);
        if (u.x == dx[u.t] && i == dy[u.t])
          push({u.t + 1, u.x, i, u.p}, b1);
        else
          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;
            if (xx == dx[u.t] && yy == dy[u.t])
              push({u.t + 1, xx, yy, u.p}, b1);
            else
              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;
          if (xx == dx[u.t] && yy == dy[u.t])
            push({u.t + 1, xx, yy, u.p}, b1);
          else
            push({u.t, xx, yy, u.p}, b1);
        }
    }
    for (register int i = 0; i <= 2; i++)
      if (dis[u.t][u.x][u.y][i] > a1) push({u.t, u.x, u.y, i}, a1);
  }
  cout << ans / 1000000 << ' ' << ans % 1000000;
  return 0;
}
