import numpy as np
import collections

N = int(input())
Plist = list(map(int , input().split()))

point_array = np.empty((N+2,N+2), dtype = int)

for i in range(N+2):
    for j in range(N+2):
        point_array[i][j] = min(i-1, j-1, N+2-i-2, N+2-j-2)
        if(point_array[i][j] == -1):
            point_array[i][j] = 0

#print(point_array)

calcDeque = collections.deque()
for P in Plist:
    calcDeque.append(P)

ans = 0
while len(calcDeque) != 0:
    toridashi = calcDeque.popleft()

    i = (toridashi) // N 
    j = (toridashi) % N
#    print(i,j)
    ans += point_array[i][j]
    if(point_array[i][j-1] > point_array[i][j]):
        point_array[i][j-1] = min(point_array[i][j+1], point_array[i+1][j], point_array[i-1][j]) +1
        calcDeque.appendleft(i * N + j - 1)

    if(point_array[i-1][j] > point_array[i][j]):
        point_array[i-1][j] = min(point_array[i][j+1], point_array[i+1][j], point_array[i][j-1]) +1
        calcDeque.appendleft((i-1) * N + j)

    if(point_array[i+1][j] > point_array[i][j]):
        point_array[i+1][j] = min(point_array[i][j+1], point_array[i][j-1], point_array[i-1][j]) +1
        calcDeque.appendleft((i+1) * N + j)

    if(point_array[i][j+1] > point_array[i][j]):
        point_array[i][j+1] = min(point_array[i][j-1], point_array[i+1][j], point_array[i-1][j]) +1
        calcDeque.appendleft(i * N + j)

    point_array[i][j] = 0
#    print(point_array)
#    print(ans)

print(ans)