#include <bits/stdc++.h>
using namespace std;
const int u1[8] = {1, 2, 2, 1, -1, -2, -2, -1};
const int u2[8] = {2, 1, -1, -2, -2, -1, 1, 2};
int n, s, t, dl[2000], a[20][20];
vector<int> p[2000];
struct pr {
  int x, y;
} ans, d[2000];
bool operator<(pr x, pr y) {
  if (x.x == y.x) return x.y < y.y;
  return x.x < y.x;
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (n); j++) scanf("%d", &a[i][j]);
  for (int i = (1); i <= (n * n); i++) {
    p[i].push_back(i + n * n);
    p[i].push_back(i + n * n * 2);
    p[i + n * n].push_back(i);
    p[i + n * n].push_back(i + n * n * 2);
    p[i + n * n * 2].push_back(i);
    p[i + n * n * 2].push_back(i + n * n);
  }
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (n); j++) {
      for (int k = (0); k <= (8); k++) {
        int i1 = i + u1[k], j1 = j + u2[k];
        if ((i1 < 1) || (i1 > n) || (j1 < 1) || (j1 > n)) continue;
        p[a[i][j]].push_back(a[i1][j1]);
      }
      for (int k = (1); k <= (n); k++)
        if (k != i) {
          int r = k + j - i;
          if ((r < 1) || (r > n)) continue;
          p[a[i][j] + n * n].push_back(a[k][r] + n * n);
        }
      for (int k = (1); k <= (n); k++)
        if (k != i) {
          int r = i + j - k;
          if ((r < 1) || (r > n)) continue;
          p[a[i][j] + n * n].push_back(a[k][r] + n * n);
        }
      for (int k = (1); k <= (n); k++)
        if (k != i) p[a[i][j] + n * n * 2].push_back(a[k][j] + n * n * 2);
      for (int k = (1); k <= (n); k++)
        if (k != j) p[a[i][j] + n * n * 2].push_back(a[i][k] + n * n * 2);
    }
  for (int i = (1); i <= (n * n - 1); i++) {
    s = t = 0;
    for (int j = (1); j <= (n * n * 3); j++)
      if (j % (n * n) != i)
        d[j] = {1000000000, 1000000000};
      else
        dl[++t] = j;
    for (; s <= t; s++)
      for (auto i : p[dl[s]]) {
        if (d[i].x == 1000000000) dl[++t] = i;
        pr r = d[dl[s]];
        r.x++;
        if (!(abs(dl[s] - i) % (n * n))) r.y++;
        if (r < d[i]) d[i] = r;
      }
  }
  ans = {1000000000, 1000000000};
  for (int i = (1); i <= (3); i++)
    if (d[n * n * i] < ans) ans = d[n * n * i];
  printf("%d %d", ans.x, ans.y);
}
