#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
import numpy as np

# input
N = int(input())
P = (input().split())

#process
S = np.zeros((N, N))
ans = 0
for p in P:
    row = math.ceil(int(p)/N) - 1
    col = (N - 1) if (math.ceil(int(p)%N) - 1) == -1 else math.ceil(int(p)%N) - 1
    S[row][col] = 1
    up = S[row,:col]
    down = S[row,col+1:]
    left = S[:row,col]
    right = S[row+1:,col]
    if len(up) <= 0 or len(down) <= 0 or len(left) <= 0 or len(right) <= 0 :
        continue
    else:
        minCount = [np.count_nonzero(up == 0),np.count_nonzero(down == 0),np.count_nonzero(left == 0),np.count_nonzero(right == 0)]
        ans = ans + min(minCount)

#output
print(ans)