#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, sits = 0, y;
  cin >> n;
  y = n * n + 1;
  int a[1000];
  for (int i = 1; i <= y; i++) {
    a[i] = 1;
  }
  for (int i = 0; i < y - 1; i++) {
    cin >> x;
    if (x <= n || x >= n * (n - 1) || x % n == 0 || x % n == 1) {
      a[x] = 0;
    } else {
      int c = 0, b = 0, p = 0, q = 0, cnt = INT_MAX;
      for (int j = x / n * n + 1; j < x; j++) {
        c += a[j];
      }
      cnt = min(c, cnt);
      for (int j = x + 1; j <= (x / n + 1) * n; j++) {
        b += a[j];
      }
      cnt = min(b, cnt);
      for (int j = x - n; j > 1; j -= n) {
        p += a[j];
      }
      cnt = min(p, cnt);
      for (int j = x + n; j < y; j += n) {
        q += a[j];
      }
      cnt = min(q, cnt);
      sits += cnt;
      a[x] = 0;
    }
  }
  cout << sits << endl;
}
