#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 47;
const long long LINF = (long long)INF * INF;
const int MAX = 2e5;
const double EPS = 1e-9;
const double PI = acos(-1.);
int n;
int a[10][10];
int dx[8] = {2, 2, 1, -1, -2, -2, -1, 1};
int dy[8] = {1, -1, -2, -2, -1, 1, 2, 2};
pair<int, int> dpT[100][10][10][3][212];
bool ok(int x, int y) {
  if (min(x, y) < 0) return false;
  if (max(x, y) >= n) return false;
  return true;
}
pair<int, int> dp(int cur, int x, int y, int fig, int steps) {
  if (steps == 212) {
    return make_pair(INF, INF);
  }
  if (cur == n * n) {
    return make_pair(0, 0);
  }
  if (dpT[cur][x][y][fig][steps] != make_pair(-1, -1)) {
    return dpT[cur][x][y][fig][steps];
  }
  if (a[x][y] == cur) {
    return dpT[cur][x][y][fig][steps] = dp(cur + 1, x, y, fig, steps);
  }
  pair<int, int> best = make_pair(INF, INF);
  if (fig != 0) {
    pair<int, int> a = dp(cur, x, y, 0, steps + 1);
    best = min(best, make_pair(a.first + 1, a.second + 1));
  }
  if (fig != 1) {
    pair<int, int> a = dp(cur, x, y, 1, steps + 1);
    best = min(best, make_pair(a.first + 1, a.second + 1));
  }
  if (fig != 2) {
    pair<int, int> a = dp(cur, x, y, 2, steps + 1);
    best = min(best, make_pair(a.first + 1, a.second + 1));
  }
  if (fig == 0) {
    for (int i = (0); i < (8); ++i) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (ok(nx, ny)) {
        pair<int, int> a = dp(cur, nx, ny, fig, steps + 1);
        best = min(best, make_pair(a.first + 1, a.second));
      }
    }
  }
  if (fig == 1) {
    for (int i = (-n); i < (n + 1); ++i) {
      if (!i) continue;
      int nx = x + i;
      int ny = y;
      if (ok(nx, ny)) {
        pair<int, int> a = dp(cur, nx, ny, fig, steps + 1);
        best = min(best, make_pair(a.first + 1, a.second));
      }
      nx = x;
      ny = y + i;
      if (ok(nx, ny)) {
        pair<int, int> a = dp(cur, nx, ny, fig, steps + 1);
        best = min(best, make_pair(a.first + 1, a.second));
      }
    }
  }
  if (fig == 2) {
    for (int i = (-n); i < (n + 1); ++i) {
      if (!i) continue;
      int nx = x + i;
      int ny = y + i;
      if (ok(nx, ny)) {
        pair<int, int> a = dp(cur, nx, ny, fig, steps + 1);
        best = min(best, make_pair(a.first + 1, a.second));
      }
      nx = x - i;
      ny = y + i;
      if (ok(nx, ny)) {
        pair<int, int> a = dp(cur, nx, ny, fig, steps + 1);
        best = min(best, make_pair(a.first + 1, a.second));
      }
    }
  }
  return dpT[cur][x][y][fig][steps] = best;
}
int main() {
  ios_base::sync_with_stdio(0);
  memset(dpT, -1, sizeof(dpT));
  cin >> n;
  int x, y;
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (n); ++j) {
      cin >> a[i][j];
      a[i][j]--;
      if (a[i][j] == 0) {
        x = i;
        y = j;
      }
    }
  }
  pair<int, int> best = make_pair(INF, INF);
  best = min(best, dp(1, x, y, 0, 0));
  best = min(best, dp(1, x, y, 1, 0));
  best = min(best, dp(1, x, y, 2, 0));
  cout << best.first << ' ' << best.second << endl;
}
