n = int(input())
p = list(map(int,input().split()))

grid = [[i for i in range(1+j,n+j+1)]for j in range(0,n**2,n)]
end = []
madlist = []
ans = 0
for i in range(len(p)):
    x = p[i]//n if p[i]%n != 0 else p[i]//n-1
    y = (p[i]-1)%n
    mad1 = 0
    mad2 = 0
    mad3 = 0
    mad4 = 0
    dx = 1
    while x+dx <= n-1:
        if grid[x+dx][y] not in end:
            mad1 += 1
        dx += 1

    dx = -1
    while x + dx >= 0:
        if grid[x + dx][y] not in end:
            mad2 += 1
        dx -= 1
    dy = 1
    while y + dy <= n-1:
        if grid[x][y+dy] not in end:
            mad3 += 1
        dy += 1
            
    dy = -1
    while y + dy >= 0:
        if grid[x][y+dy] not in end:
            mad4 += 1
        dy -= 1
    if min(mad1,mad2,mad3,mad4) != 0:
        ans += min(mad1,mad2,mad3,mad4)
        #madlist.append(p[i])
    end.append(p[i])
print(ans)
#print(madlist)