#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
void pre() {}
int arr[500][500];
bool isp[500][500];
long long q[1000];
int n;
bool isvalid(int i, int j) {
  if (i >= n || i < 0 || j < 0 || j >= n) {
    return false;
    ;
  }
  return true;
}
void update(int i, int j) {
  if (!isp[i][j]) {
    if (isvalid(i + 1, j))
      if (arr[i + 1][j] == arr[i][j] + 1) {
        arr[i + 1][j]--;
        update(i + 1, j);
      }
    if (isvalid(i - 1, j))
      if (arr[i - 1][j] == arr[i][j] + 1) {
        arr[i - 1][j]--;
        update(i - 1, j);
      }
    if (isvalid(i, j + 1))
      if (arr[i][j + 1] == arr[i][j] + 1) {
        arr[i][j + 1]--;
        update(i, j + 1);
      }
    if (isvalid(i, j - 1))
      if (arr[i][j - 1] == arr[i][j] + 1) {
        arr[i][j - 1]--;
        update(i, j - 1);
      }
  } else {
    if (isvalid(i + 1, j))
      if (arr[i + 1][j] == arr[i][j] + 2) {
        arr[i + 1][j]--;
        update(i + 1, j);
      }
    if (isvalid(i - 1, j))
      if (arr[i - 1][j] == arr[i][j] + 2) {
        arr[i - 1][j]--;
        update(i - 1, j);
      }
    if (isvalid(i, j + 1))
      if (arr[i][j + 1] == arr[i][j] + 2) {
        arr[i][j + 1]--;
        update(i, j + 1);
      }
    if (isvalid(i, j - 1))
      if (arr[i][j - 1] == arr[i][j] + 2) {
        arr[i][j - 1]--;
        update(i, j - 1);
      }
  }
}
void solve() {
  cin >> n;
  long long m = n * n;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n - i; j++) {
      arr[i][j] = i;
      arr[n - i - 1][j] = i;
      arr[j][i] = i;
      arr[j][n - i - 1] = i;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      isp[i][j] = 1;
    }
  }
  long long ans = 0;
  long long a, b;
  for (int i = 0; i < m; i++) {
    cin >> q[i];
    q[i]--;
    a = q[i] / n;
    b = q[i] - n * (q[i] / n);
    ans += arr[a][b];
    isp[a][b] = 0;
    update(a, b);
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  pre();
  long long int num = 1;
  for (long long int i = 0; i < num; i++) {
    solve();
  }
}
