#include <bits/stdc++.h>
using namespace std;
int N;
struct Point {
  int i, j;
  Point operator+(const Point &o) const { return {i + o.i, j + o.j}; }
  bool chk() { return (1 <= i && i <= N && 1 <= j && j <= N); }
};
int nummove[3] = {8, 4, 4};
Point mov[3][10] = {
    {{2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, 2}, {-1, 2}, {1, -2}, {-1, -2}},
    {{1, 0}, {0, 1}, {-1, 0}, {0, -1}},
    {{1, 1}, {-1, -1}, {1, -1}, {-1, 1}}};
struct Node {
  Point pos;
  int done;
  int s;
  pair<int, int> c;
  bool operator<(const Node &o) const { return c > o.c; }
};
Point idx[105];
int inp[14][14];
pair<int, int> dist[14][14][105][4];
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      scanf("%d", inp[i] + j);
      idx[inp[i][j]] = {i, j};
    }
  }
  memset(dist, 50, sizeof dist);
  dist[idx[1].i][idx[1].j][1][0] = dist[idx[1].i][idx[1].j][1][1] =
      dist[idx[1].i][idx[1].j][1][2] = pair<int, int>(0, 0);
  priority_queue<Node> q;
  q.push({idx[1], 1, 0, pair<int, int>(0, 0)});
  q.push({idx[1], 1, 1, pair<int, int>(0, 0)});
  q.push({idx[1], 1, 2, pair<int, int>(0, 0)});
  while (!q.empty()) {
    Node cur = q.top();
    q.pop();
    if (cur.done == N * N) {
      return !printf("%d %d", cur.c.first, cur.c.second);
    }
    for (int i = 0; i < 3; i++)
      if (cur.s != i) {
        pair<int, int> c = dist[cur.pos.i][cur.pos.j][cur.done][cur.s],
                       &nxt = dist[cur.pos.i][cur.pos.j][cur.done][i];
        if (nxt > pair<int, int>(c.first + 1, c.second + 1)) {
          nxt = {c.first + 1, c.second + 1};
          q.push({cur.pos, cur.done, i, nxt});
        }
      }
    for (int k = 0; k < nummove[cur.s]; k++) {
      Point n = cur.pos + mov[cur.s][k];
      int done = cur.done;
      while (1) {
        if (!n.chk()) break;
        pair<int, int> c = dist[cur.pos.i][cur.pos.j][done][cur.s],
                       &nxt = dist[n.i][n.j]
                                  [done + (inp[n.i][n.j] == done + 1 ? 1 : 0)]
                                  [cur.s];
        if (nxt > pair<int, int>(c.first + 1, c.second)) {
          nxt = {c.first + 1, c.second};
          q.push({n, done + (inp[n.i][n.j] == done + 1 ? 1 : 0), cur.s, nxt});
        }
        if (cur.s == 0) break;
        n = n + mov[cur.s][k];
      }
    }
  }
}
