#include <bits/stdc++.h>
using namespace std;
const int inf = 1000 * 1000;
const int mx = 105;
int d1[] = {2, 2, 1, 1, -2, -2, -1, -1};
int d2[] = {-1, 1, -2, 2, 1, -1, 2, -2};
vector<vector<pair<int, int> > > mov(4);
pair<int, int> position[mx];
int arr[12][12];
int n;
pair<int, int> dp[12][12][mx][4];
struct Node {
  int r, c, mv, sw, idx, pw;
  Node(){};
  Node(int a, int b, int d, int e, int f, int g) {
    r = a;
    c = b;
    mv = d;
    sw = e;
    idx = f;
    pw = g;
  }
  bool operator<(const struct Node &a) const {
    if (mv == a.mv) return sw > a.sw;
    return mv > a.mv;
  }
};
bool valid(int r, int c) {
  if (r < 1 || c < 1 || r > n || c > n) return 0;
  return 1;
}
void bolo(pair<int, int> one) {
  int i, len, q, r, c, tool, nxt, x, y, mv, sw;
  priority_queue<Node> pq;
  Node now = Node(one.first, one.second, 0, 0, 2, 0);
  pq.push(now);
  now = Node(one.first, one.second, 0, 0, 2, 1);
  pq.push(now);
  now = Node(one.first, one.second, 0, 0, 2, 2);
  pq.push(now);
  Node temp;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int id = 1; id < mx; id++) {
        for (int pp = 0; pp < 3; pp++) {
          dp[i][j][id][pp] = make_pair(inf, inf);
        }
      }
    }
  }
  dp[one.first][one.second][2][0] = make_pair(0, 0);
  dp[one.first][one.second][2][1] = make_pair(0, 0);
  dp[one.first][one.second][2][2] = make_pair(0, 0);
  int done = n * n + 1;
  while (!pq.empty()) {
    now = pq.top();
    pq.pop();
    r = now.r;
    c = now.c;
    mv = now.mv;
    sw = now.sw;
    nxt = now.idx;
    tool = now.pw;
    if (nxt == done) break;
    len = mov[tool].size();
    for (i = 0; i < len; i++) {
      x = r + mov[tool][i].first;
      y = c + mov[tool][i].second;
      if (!valid(x, y)) continue;
      if (arr[x][y] == nxt) {
        if (dp[x][y][nxt + 1][tool].first > mv + 1) {
          dp[x][y][nxt + 1][tool].first = mv + 1;
          dp[x][y][nxt + 1][tool].second = sw;
          pq.push(Node(x, y, mv + 1, sw, nxt + 1, tool));
        } else if ((dp[x][y][nxt + 1][tool].first == mv + 1) &&
                   (dp[x][y][nxt + 1][tool].second > sw)) {
          dp[x][y][nxt + 1][tool].first = mv + 1;
          dp[x][y][nxt + 1][tool].second = sw;
          pq.push(Node(x, y, mv + 1, sw, nxt + 1, tool));
        }
      } else {
        if ((dp[x][y][nxt][tool].first > mv + 1) ||
            (dp[x][y][nxt][tool].first == (mv + 1) &&
             dp[x][y][nxt][tool].second > sw)) {
          dp[x][y][nxt][tool].first = mv + 1;
          dp[x][y][nxt][tool].second = sw;
          pq.push(Node(x, y, mv + 1, sw, nxt, tool));
        }
      }
    }
    now.mv++;
    now.sw++;
    now.pw++;
    now.pw %= 3;
    if ((dp[r][c][nxt][now.pw].first > now.mv) ||
        (dp[r][c][nxt][now.pw].first == now.mv &&
         dp[r][c][nxt][now.pw].second > now.sw)) {
      dp[r][c][nxt][now.pw].first = now.mv;
      dp[r][c][nxt][now.pw].second = now.sw;
      pq.push(now);
    }
    now.pw++;
    now.pw %= 3;
    if ((dp[r][c][nxt][now.pw].first > now.mv) ||
        (dp[r][c][nxt][now.pw].first == now.mv &&
         dp[r][c][nxt][now.pw].second > now.sw)) {
      dp[r][c][nxt][now.pw].first = now.mv;
      dp[r][c][nxt][now.pw].second = now.sw;
      pq.push(now);
    }
  }
}
int main() {
  int i, j, k, p, q;
  scanf("%d", &n);
  q = n * n;
  pair<int, int> inp, oup;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      scanf("%d", &p);
      arr[i][j] = p;
      if (p == 1) inp = make_pair(i, j);
      if (p == q) oup = make_pair(i, j);
    }
  }
  for (i = 0; i < 8; i++) {
    mov[0].push_back(make_pair(d1[i], d2[i]));
  }
  for (i = 1; i <= n; i++) {
    mov[1].push_back(make_pair(i, 0));
    mov[1].push_back(make_pair(-i, 0));
    mov[1].push_back(make_pair(0, i));
    mov[1].push_back(make_pair(0, -i));
  }
  for (i = 1; i <= n; i++) {
    mov[2].push_back(make_pair(i, i));
    mov[2].push_back(make_pair(i, -i));
    mov[2].push_back(make_pair(-i, i));
    mov[2].push_back(make_pair(-i, -i));
  }
  bolo(inp);
  pair<int, int> now, ans = make_pair(inf, inf);
  for (i = 0; i < 3; i++) {
    now = dp[oup.first][oup.second][q + 1][i];
    if ((now.first < ans.first) ||
        (now.first == ans.first && now.second < ans.second)) {
      ans = now;
    }
  }
  printf("%d %d\n", ans.first, ans.second);
  return 0;
}
