#include <bits/stdc++.h>
using namespace std;
int SUM;
int N;
void dfs(int nh, int nw, vector<vector<int>>& seat, vector<vector<int>>& seen,
         int h, int w, int v_sum) {
  seen.at(nh).at(nw) = 1;
  vector<int> move_h(4);
  vector<int> move_w(4);
  move_h = {1, 0, -1, 0};
  move_w = {0, 1, 0, -1};
  int fra = 0;
  if (nh == 0 || nw == 0 || nh == N - 1 || nw == N - 1) {
    seat.at(h).at(w) = 0;
    if (v_sum < SUM) SUM = v_sum - 1;
  } else {
    for (int i = 0; i < 4; i++) {
      int new_h = nh + move_h.at(i);
      int new_w = nw + move_w.at(i);
      if (seen.at(new_h).at(new_w) == 1) {
        fra++;
        continue;
      }
      if (seat.at(new_h).at(new_w) == 0) {
        dfs(new_h, new_w, seat, seen, h, w, v_sum);
      } else {
        fra++;
      }
    }
    if (fra == 4) {
      for (int i = 0; i < 4; i++) {
        int new_h = nh + move_h.at(i);
        int new_w = nw + move_w.at(i);
        if (seen.at(new_h).at(new_w) == 1) continue;
        v_sum++;
        dfs(new_h, new_w, seat, seen, h, w, v_sum);
      }
    }
  }
}
int main() {
  cin >> N;
  int n2 = N * N;
  vector<vector<int>> seat(N, vector<int>(N, 1));
  vector<int> ord(n2);
  for (int& x : ord) {
    cin >> x;
  }
  int all_sum = 0;
  vector<vector<int>> seen(N, vector<int>(N, 0));
  for (int i = 0; i < n2; i++) {
    int ac = ord.at(i);
    int nh;
    int nw;
    if (ac % N == 0) {
      nh = ac / N - 1;
      nw = N - 1;
    } else {
      nh = ac / N;
      nw = ac % N - 1;
    }
    SUM = n2;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        seen.at(i).at(j) = 0;
      }
    }
    dfs(nh, nw, seat, seen, nh, nw, 0);
    cout << SUM << endl;
    all_sum += SUM;
  }
  cout << all_sum << endl;
}
