#include <bits/stdc++.h>
using namespace std;
const int MXN = (int)2e5 + 100;
const int INF = (int)1e9 + 7;
const long long LINF = (long long)1e18 + 10;
const double EPS = (double)1e-9;
const double PI = (double)acos(-1.0);
const int dx_k[] = {2, 2, 1, 1, -2, -2, -1, -1};
const int dy_k[] = {-1, 1, 2, -2, 1, -1, 2, -2};
pair<int, int> d[111][11][11][3];
int a[11][11];
int s_x, s_y, n;
pair<int, int> loc[111];
bool check(int first, int second) {
  return (first >= 0 && second >= 0 && first < n && second < n);
}
vector<pair<int, int> > getPos(int first, int second, int fig) {
  vector<pair<int, int> > ret;
  if (!fig) {
    int nx, ny;
    for (int i = 0; i < 8; ++i) {
      nx = first + dx_k[i];
      ny = second + dy_k[i];
      if (check(nx, ny)) {
        ret.push_back(make_pair(nx, ny));
      }
    }
  } else if (fig == 1) {
    for (int i = 0; i < n; ++i) {
      if (first != i) ret.push_back(make_pair(i, second));
      if (second != i) ret.push_back(make_pair(first, i));
    }
  } else {
    for (int i = 1; check(first + i, second + i); ++i) {
      ret.push_back(make_pair(first + i, second + i));
    }
    for (int i = 1; check(first - i, second + i); ++i) {
      ret.push_back(make_pair(first - i, second + i));
    }
    for (int i = 1; check(first + i, second - i); ++i) {
      ret.push_back(make_pair(first + i, second - i));
    }
    for (int i = 1; check(first - i, second - i); ++i) {
      ret.push_back(make_pair(first - i, second - i));
    }
  }
  return ret;
}
pair<int, int> add(pair<int, int> a, pair<int, int> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      scanf("%d", &a[i][j]);
      loc[a[i][j]] = make_pair(i, j);
    }
  }
  for (int i = 0; i <= n * n; ++i) {
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < n; ++k) {
        d[i][j][k][0] = d[i][j][k][1] = d[i][j][k][2] = make_pair(INF, INF);
      }
    }
  }
  for (int i = 0; i < 3; ++i)
    d[1][loc[1].first][loc[1].second][i] = make_pair(0, 0);
  for (int step = 1; step < n * n; ++step) {
    for (int tmp = 0; tmp < 10; ++tmp) {
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
          for (int fig1 = 0; fig1 < 3; ++fig1) {
            for (int fig2 = 0; fig2 < 3; ++fig2) {
              vector<pair<int, int> > v = getPos(i, j, fig1);
              for (auto it : v) {
                d[step][i][j][fig1] =
                    min(add(d[step][it.first][it.second][fig2],
                            make_pair(1 + (fig1 != fig2), fig1 != fig2)),
                        d[step][i][j][fig1]);
              }
            }
          }
        }
      }
    }
    int first = loc[step + 1].first, second = loc[step + 1].second;
    for (int fig1 = 0; fig1 < 3; ++fig1) {
      for (int fig2 = 0; fig2 < 3; ++fig2) {
        vector<pair<int, int> > v = getPos(first, second, fig1);
        for (auto it : v) {
          d[step + 1][first][second][fig1] =
              min(add(d[step][it.first][it.second][fig2],
                      make_pair(1 + (fig1 != fig2), fig1 != fig2)),
                  d[step + 1][first][second][fig1]);
        }
      }
    }
  }
  pair<int, int> ans = d[n * n][loc[n * n].first][loc[n * n].second][0];
  ans = min(ans, d[n * n][loc[n * n].first][loc[n * n].second][1]);
  ans = min(ans, d[n * n][loc[n * n].first][loc[n * n].second][2]);
  printf("%d %d", ans.first, ans.second);
  return 0;
}
