#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const int N = 10;
const int A = 3;
const int S = 4;
int pos[N * N];
std::vector<int> g[A][N * N];
int dist[A][N * N][N * N];
std::pair<int, int> dp[N * N][S][N * N][A];
std::pair<int, int> res[N * N][A];
int n;
inline int enc(int i, int j) { return i * n + j; }
inline void add_edge(int ind, int i, int j, int k, int l) {
  g[ind][enc(i, j)].push_back(enc(k, l));
}
void bfs(int v, std::vector<int> *g, int *dist) {
  memset(dist, 0x3f, 4 * N * N);
  std::queue<int> q;
  dist[v] = 0;
  q.push(v);
  while (!q.empty()) {
    v = q.front();
    q.pop();
    for (int i = 0; i < (int)g[v].size(); ++i)
      if (dist[g[v][i]] == INF) {
        dist[g[v][i]] = dist[v] + 1;
        q.push(g[v][i]);
      }
  }
}
void prep() {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < n; ++k)
        for (int l = 0; l < n; ++l)
          if (i != k || j != l) {
            if (abs(k - i) == 2 && abs(l - j) == 1 ||
                abs(k - i) == 1 && abs(l - j) == 2)
              add_edge(0, i, j, k, l);
            if (abs(k - i) == abs(l - j)) add_edge(1, i, j, k, l);
            if (i == k || l == j) add_edge(2, i, j, k, l);
          }
    }
  }
  for (int i = 0; i < A; ++i)
    for (int j = 0; j < n * n; ++j) bfs(j, g[i], dist[i][j]);
}
inline std::pair<int, int> get(std::pair<int, int> from, int fi, int f, int se,
                               int t) {
  return std::make_pair(from.first + dist[f][fi][se] + (f != t),
                        from.second + (f != t));
}
int main() {
  scanf("%d", &n);
  prep();
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) {
      int v;
      scanf("%d", &v);
      pos[v - 1] = enc(i, j);
    }
  for (int i = 0; i < N * N * N * N * S * A; ++i)
    *(***dp + i) = std::make_pair(INF, INF);
  for (int i = 0; i < N * N * A; ++i) *(*res + i) = std::make_pair(INF, INF);
  for (int i = 0; i < A; ++i) res[0][i] = std::make_pair(0, 0);
  for (int i = 0; i < n * n - 1; ++i) {
    for (int j = 0; j < n * n; ++j)
      for (int f = 0; f < A; ++f)
        for (int t = 0; t < A; ++t)
          dp[i][0][j][t] =
              std::min(dp[i][0][j][t], get(res[i][f], pos[i], f, j, t));
    for (int s = 1; s < S; ++s)
      for (int j = 0; j < n * n; ++j)
        for (int k = 0; k < n * n; ++k)
          for (int f = 0; f < A; ++f)
            for (int t = 0; t < A; ++t)
              dp[i][s][k][t] =
                  std::min(dp[i][s][k][t], get(dp[i][s - 1][j][f], j, f, k, t));
    for (int j = 0; j < n * n; ++j)
      for (int s = 0; s < S; ++s)
        for (int f = 0; f < A; ++f)
          for (int t = 0; t < A; ++t)
            res[i + 1][t] = std::min(res[i + 1][t],
                                     get(dp[i][s][j][f], j, f, pos[i + 1], t));
  }
  std::pair<int, int> ans(INF, INF);
  for (int i = 0; i < A; ++i) ans = min(ans, res[n * n - 1][i]);
  printf("%d %d\n", ans.first, ans.second);
  return 0;
}
