from collections import deque

N = int(eval(input()))

A = [int(a)-1 for a in input().split()]

M = N + 2

X = [max(min(i-1, j-1, M-2-i, M-2-j), -1) for j in range(M) for i in range(M)]

Y = [min(x, 0) + 1 for x in X]



def calc(i0):

    h = X[i0]

    if h < 0: return

    Q = deque([(i0, h)])

    X[i0] -= 1

    Y[i0] = 0

    dd = (-1, 1, M, -M)

    while Q:

        i, h = deque.popleft(Q)

        for d in dd:

            j = i + d

            y = Y[j]

            if X[j] >= h + y:

                X[j] -= 1

                deque.append(Q, (j, h + y))

ans = 0

for a in A:

    aa = (a // N + 1) * M + a % N + 1

    ans += X[aa]

    calc(aa)

print(ans)
from collections import deque

N = int(eval(input()))

A = [int(a)-1 for a in input().split()]

M = N + 2

X = [max(min(i-1, j-1, M-2-i, M-2-j), -1) for j in range(M) for i in range(M)]

Y = [min(x, 0) + 1 for x in X]



ans = 0

for a in A:

    aa = (a // N + 1) * M + a % N + 1

    ans += X[aa]

    h = X[aa]

    if h < 0: continue

    Q = deque([(aa, h)])

    X[aa] -= 1

    Y[aa] = 0

    dd = (-1, 1, M, -M)

    while Q:

        i, h = deque.popleft(Q)

        for d in dd:

            j = i + d

            y = Y[j]

            if X[j] >= h + y:

                X[j] -= 1

                deque.append(Q, (j, h + y))

print(ans)
from collections import deque

N = int(eval(input()))
A = [int(a) - 1 for a in input().split()]
M = N + 2
X = [
    max(min(i - 1, j - 1, M - 2 - i, M - 2 - j), -1) for j in range(M) for i in range(M)
]
Y = [min(x, 0) + 1 for x in X]


def calc(i0):
    h = X[i0]
    if h < 0:
        return
    Q = deque([(i0, h)])
    X[i0] -= 1
    Y[i0] = 0
    dd = (-1, 1, M, -M)
    while Q:
        i, h = deque.popleft(Q)
        for d in dd:
            j = i + d
            y = Y[j]
            if X[j] >= h + y:
                X[j] -= 1
                deque.append(Q, (j, h + y))


ans = 0
for a in A:
    aa = (a // N + 1) * M + a % N + 1
    ans += X[aa]
    calc(aa)
print(ans)

from collections import deque

N = int(eval(input()))
A = [int(a) - 1 for a in input().split()]
M = N + 2
X = [
    max(min(i - 1, j - 1, M - 2 - i, M - 2 - j), -1) for j in range(M) for i in range(M)
]
Y = [min(x, 0) + 1 for x in X]
ans = 0
for a in A:
    aa = (a // N + 1) * M + a % N + 1
    ans += X[aa]
    h = X[aa]
    if h < 0:
        continue
    Q = deque([(aa, h)])
    X[aa] -= 1
    Y[aa] = 0
    dd = (-1, 1, M, -M)
    while Q:
        i, h = deque.popleft(Q)
        for d in dd:
            j = i + d
            y = Y[j]
            if X[j] >= h + y:
                X[j] -= 1
                deque.append(Q, (j, h + y))
print(ans)

- - -def calc(i0): -    h = X[i0] +ans = 0 +for a in A: +    aa = (a // N + 1) * M + a % N + 1 +    ans += X[aa] +    h = X[aa] -        return -    Q = deque([(i0, h)]) -    X[i0] -= 1 -    Y[i0] = 0 +        continue +    Q = deque([(aa, h)]) +    X[aa] -= 1 +    Y[aa] = 0 - - -ans = 0 -for a in A: -    aa = (a // N + 1) * M + a % N + 1 -    ans += X[aa] -    calc(aa)