#include <bits/stdc++.h>
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;
using namespace std;
template <class TH>
void _dbg(const char* sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char* sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
const long long N = 10, M = 100;
const long long rook = 0, knight = 1, bishop = 2;
pair<long long, long long> dp[4 * M][N + 1][N + 1][3];
long long walk[N + 1][N + 1];
pair<long long, long long> operator+(pair<long long, long long> a,
                                     pair<long long, long long> b) {
  return {a.first + b.first, a.second + b.second};
}
vector<pair<long long, long long> > board;
bool can_move(pair<long long, long long> c1, pair<long long, long long> c2,
              int piece) {
  switch (piece) {
    case rook:
      return c1.first == c2.first or c1.second == c2.second;
    case bishop:
      return abs(c1.first - c2.first) == abs(c1.second - c2.second);
    case knight:
      return (abs(c2.first - c1.first) == 2 and
              abs(c2.second - c1.second) == 1) or
             (abs(c2.first - c1.first) == 1 and
              abs(c2.second - c1.second) == 2);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  long long m = n * n;
  for (long long i = (long long)0; i < (long long)n; i++) {
    for (long long j = (long long)0; j < (long long)n; j++) {
      board.push_back({i, j});
      cin >> walk[i][j];
      if (0) cout << walk[i][j] << " \n"[j == n - 1];
      if (walk[i][j] == 1) {
        for (long long p = (long long)0; p < (long long)3; p++) {
          dp[0][i][j][p] = {1, 0};
        }
      }
    }
  }
  pair<long long, long long> ans = {IINF, IINF};
  for (long long i = (long long)1; i < (long long)4 * m; i++) {
    for (auto& c : board) {
      for (long long p = (long long)0; p < (long long)3; p++) {
        if (i) {
          for (long long p0 = (long long)0; p0 < (long long)3; p0++) {
            auto cand =
                (dp[i - 1][c.first][c.second][p0].first + 1 ==
                 walk[c.first][c.second])
                    ? dp[i - 1][c.first][c.second][p0] + make_pair(1, -1)
                    : dp[i - 1][c.first][c.second][p0] + make_pair(0, -1);
            dp[i][c.first][c.second][p] =
                max(dp[i][c.first][c.second][p], cand);
          }
          for (auto& c0 : board) {
            if (can_move(c0, c, p)) {
              auto cand =
                  (dp[i - 1][c0.first][c0.second][p].first + 1 ==
                   walk[c.first][c.second])
                      ? dp[i - 1][c0.first][c0.second][p] + make_pair(1, 0)
                      : dp[i - 1][c0.first][c0.second][p];
              dp[i][c.first][c.second][p] =
                  max(dp[i][c.first][c.second][p], cand);
            }
          }
        }
        if (dp[i][c.first][c.second][p].first == m) {
          ans = min(ans, make_pair(i, -dp[i][c.first][c.second][p].second));
        }
        (i, c.first, c.second, p, dp[i][c.first][c.second][p].first,
         dp[i][c.first][c.second][p].second);
      }
    }
  }
  cout << ans.first << " " << ans.second << "\n";
  return 0;
}
