import sys
import numpy as np
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
P = np.array(list(map(int, readline().split())))

data = np.ones((N,N))
ans = 0

# 座ってる場所のindex判定
def seat_index(seat_num):
  div,mod = divmod(seat_num, N)
  if mod % N == 0:
    col = div-1
    row = N-1
  else:
    col = div
    row = mod-1
  return [col,row]

# 嫌う人数判定
def check(col, row):
  data[col][row] = 0
  if col == 0 or col == N or row == 0 or row == N or np.sum(data[col,:row]) == 0 or np.sum(data[col,:row]) == 0 or np.sum(data[:col,row]) == 0 or np.sum(data[col+1:,row]) == 0:
    return 0
  else:
    return np.min(np.array([np.sum(data[col,:row]),np.sum(data[col,row:])
                       ,np.sum(data[:col,row]),np.sum(data[col:,row])]))


for i in P:
  seat_num = i
  col,row = seat_index(seat_num)
  ans += int(check(col,row))


print(ans)
