#include <bits/stdc++.h>
using namespace std;
class SSSP {
 public:
  vector<pair<int, int>> operator()(int n, int src, int dst,
                                    vector<pair<int, int>> const& a) {
    _d.clear();
    _d.resize(3 * n * n, {-1e9, 0});
    for (int t = 0; t < 3; ++t) consider(a[t], 3 * src + t);
    while (!_q.empty()) {
      pair<int, int> d = _q.top().first;
      int u = _q.top().second;
      _q.pop();
      if (d < _d[u]) continue;
      int t = u % 3;
      u /= 3;
      int ui = u / n, uj = u % n;
      --d.first;
      for (int tt = 0; tt < 3; ++tt) {
        if (tt != t) consider({d.first, d.second - 1}, 3 * u + tt);
      }
      if (t == 0) {
        for (int x = 0; x < n; ++x) {
          if (x != ui) consider(d, 3 * (x * n + uj) + t);
          if (x != uj) consider(d, 3 * (ui * n + x) + t);
        }
      } else if (t == 1) {
        for (int si = -1; si <= 1; si += 2) {
          for (int sj = -1; sj <= 1; sj += 2) {
            for (int x = 1; x < n; ++x) {
              int i = ui + si * x, j = uj + sj * x;
              if (i < 0 || i >= n || j < 0 || j >= n) break;
              consider(d, 3 * (i * n + j) + t);
            }
          }
        }
      } else {
        for (int si = -1; si <= 1; si += 2) {
          for (int sj = -1; sj <= 1; sj += 2) {
            int i = ui + si * 2, j = uj + sj;
            if (0 <= i && i < n && 0 <= j && j < n)
              consider(d, 3 * (i * n + j) + t);
            i = ui + si, j = uj + sj * 2;
            if (0 <= i && i < n && 0 <= j && j < n)
              consider(d, 3 * (i * n + j) + t);
          }
        }
      }
    }
    return {_d[3 * dst], _d[3 * dst + 1], _d[3 * dst + 2]};
  }

 private:
  void consider(pair<int, int> d, int u) {
    if (d > _d[u]) {
      _d[u] = d;
      _q.emplace(d, u);
    }
  }
  priority_queue<pair<pair<int, int>, int>> _q;
  vector<pair<int, int>> _d;
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n * n);
  for (int i = 0, x; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> x;
      a[x - 1] = i * n + j;
    }
  }
  SSSP sssp;
  vector<pair<int, int>> f(3);
  for (int i = 1; i < n * n; ++i) f = sssp(n, a[i - 1], a[i], f);
  pair<int, int> r = *max_element((f).begin(), (f).end());
  cout << -r.first << " " << -r.second << "\n";
  return 0;
}
