import numpy as np

N = int(input())

table = np.array([[1 for i in range(N)] for j in range(N)])


pattern = 0

peaple = list(map(int,input().split()))


for person in peaple:
    person -= 1
    row = person//N
    column = person%N
    table[row][column] = 0
    if column in [0,N-1] or row in [0,N-1]:
        continue;
    person_row = list(table[row])
    person_column = list(table[:,column])
    around = [sum(person_row[:column]),sum(person_row[column+1:]),sum(person_column[:row]),sum(person_column[row+1:])]
    around.sort()
    for j in around:
        if j == 0:
            break;
        else:
            pattern += j
            break;


print(pattern)