#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int limit;
int N;
vector<int> xvec{0, 0, 1, -1};
vector<int> yvec{1, -1, 0, 0};
vector<vector<int>> field;
vector<vector<bool>> checked;
int dfs(int x, int y, int dist) {
  if (min(min(x, y), N - 1 - max(x, y)) == 0) return dist;
  if (dist >= limit) return 1e9;
  int a = 1e9;
  for (int i = 0; i < (4); ++i) {
    int newx = x + xvec[i];
    int newy = y + yvec[i];
    if (checked[newx][newy]) continue;
    checked[newx][newy] = true;
    a = min(a, dfs(newx, newy, dist + field[newx][newy]));
  }
  return a;
}
int main() {
  cin >> N;
  field.resize(N + 1, vector<int>(N + 1, 1));
  checked.resize(N + 1, vector<bool>(N + 1, false));
  vector<vector<bool>> c = checked;
  cout << field.size() << endl;
  cout << field[0].size() << endl;
  ll ans = 0;
  for (int a = 0; a < (N * N); ++a) {
    int i;
    cin >> i;
    i--;
    int y = i / N;
    int x = i % N;
    limit = min(min(x, y), N - 1 - max(x, y));
    checked = c;
    checked[x][y] = true;
    ans += dfs(x, y, 0);
    field[x][y] = 0;
  }
  cout << ans << endl;
}
