import sys

sys.setrecursionlimit(10 ** 9)

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

m = [[0] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        m[i][j] = min(i, n-i-1, j, n-j-1)

def _f(i, j):
    for d in [(-1, 0), (0, 1), (1, 0), (0, -1)]:
        ii, jj = i + d[0], j + d[1]
        if 0 <= ii < n and 0 <= jj < n:
            if m[ii][jj] > m[i][j]:
                _f(ii, jj)
                m[ii][jj] = m[ii][jj] - 1

res = 0
for p in pp:
    i, j = (p-1) // n, (p-1) % n
    s = m[i][j]
    res = res + max(0, s)
    _f(i, j)
    if s > 0:
        m[i][j] = 0.5

print(res)
