INF = float("inf")
n = int(input())
P = list(map(int, input().split()))
T = [[INF] * (n+2) for _ in range(n+2)]
rest = [[1] * (n+2) for _ in range(n+2)]
ans = 0
for i in range(n+2):
    if i == 0 or i == n+1:
        for j in range(n+2):
            rest[i][j] = INF
    else:
        rest[i][0] = INF
        rest[i][n+1] = INF
        T[1][i] = 1
        T[n][i] = 1
        T[i][1] = 1
        T[n][1] = 1
def check(i,j):
    mn = min(T[i-1][j], T[i][j-1], T[i][j+1], T[i+1][j])
    tmp = mn + rest[i][j]
    if tmp < T[i][j]:
        T[i][j] = tmp

for p in P:
    s = (p-1) // n + 1
    t = (p-1) % n + 1
    rest[s][t] = 0
    if s in (1,n) or t in (1,n):
        T[s][t] = 0
        continue

    for i in range(2, n):
        for j in range(2, n):
            check(i, j)
            check(i, n-j+1)
            check(n-i+1, j)
            check(n-i+1, n-j+1)
    for i in range(2, n):
        for j in range(2, n):
            check(i, j)
            check(i, n-j+1)
            check(n-i+1, j)
            check(n-i+1, n-j+1)

    ans += T[s][t]
print(ans)