#include <bits/stdc++.h>
typedef struct {
  int now[2500];
  int hate;
  int front, back, left, right;
} zaseki;
void zaseki_set(zaseki *z, int n) {
  int i;
  for (i = 1; i <= n * n; i++) {
    z->now[i] = 1;
  }
}
void arugo(int n, int p, zaseki *z) {
  int i, mleft, mright, h;
  z->now[p] = 0;
  z->front = z->back = z->left = z->right = 0;
  i = p;
  i = i - n;
  while (i > 0) {
    if (z->now[i] == 1) z->front++;
    i = i - n;
  }
  i = p;
  i = i + n;
  while (i <= n * n) {
    if (z->now[i] == 1) z->back++;
    i = i + n;
  }
  i = p % n;
  mleft = p - i + 1;
  i = p - 1;
  while (i >= mleft) {
    if (z->now[i] == 1) z->left++;
    i--;
  }
  i = p % n;
  mright = p + n - i;
  i = p + 1;
  while (i <= mright) {
    if (z->now[i] == 1) z->right++;
    i++;
  }
  h = z->front;
  if (h > z->back)
    h = z->back;
  else if (h > z->left)
    h = z->left;
  else if (h > z->right)
    h = z->right;
  z->hate += h;
}
int main() {
  int i, N, P, n;
  zaseki *z;
  z = (zaseki *)malloc(sizeof(zaseki));
  z->hate = 0;
  scanf("%d", &N);
  zaseki_set(z, N);
  for (i = 0; i < N * N - 1; i++) {
    scanf("%d ", &P);
    arugo(N, P, z);
  }
  scanf("%d", &P);
  arugo(N, P, z);
  printf("%d\n", z->hate);
  return 0;
}
