from collections import deque
import copy
n = int(input())
order = tuple(map(lambda x:int(x)-1, input().split()))

def bfs(i_y, i_x):
    tmp_chairs = copy.deepcopy(chairs)
    queue = deque()
    start = (i_y, i_x, 0)
    queue.append(start)
    # res = []
    res = 600
    while queue:
        y, x, unlike = queue.popleft()
        flag = False
        for i in range(4):
            tmp_y = y + dy[i]
            tmp_x = x + dx[i]
            if tmp_x >= n or tmp_x < 0 or tmp_y >= n or tmp_y < 0:
                chairs[i_y][i_x] = -1
                # if res >= unlike:
                #     return unlike
                res = min(res, unlike)
                # res.append(unlike)
                flag = True
                # return unlike
            elif tmp_chairs[tmp_y][tmp_x] == -1:
                tmp_chairs[y][x] = -2
                queue.append((tmp_y, tmp_x, unlike))
                # flag = True
            # else:
            #     if tmp_chairs[tmp_y][tmp_x] != -2:
            #         if tmp_y >= n-((n//2)-1) or tmp_y < (n//2)-1 or tmp_x >= n-((n//2)-1) or tmp_x < (n//2)-1:
            #             tmp_chairs[y][x] = -2
            #             queue.append((tmp_y, tmp_x, unlike+1))
            #             flag = True
        if not flag:
            for i in range(4):
                tmp_y = y + dy[i]
                tmp_x = x + dx[i]
                if tmp_chairs[tmp_y][tmp_x] != -2:
                    if tmp_y >= n-((n//2)-1) or tmp_y < (n//2)-1 or tmp_x >= n-((n//2)-1) or tmp_x < (n//2)-1:
                        tmp_chairs[y][x] = -2
                        queue.append((tmp_y, tmp_x, unlike+1))
    # return min(res)
    return res
# 座席作成
dy = [-1, 0, 1, 0]
dx = [0, 1, 0, -1]
ans = 0
chairs = [[0] * n for _ in range(n)]
for i in range(n):
    for i_, j in enumerate(range(i*n, i*n+n)):
        chairs[i][i_] = j

for num in order:
    cnt = 0
    i_y, i_x = num//n, num%n
    ans += bfs(i_y, i_x)
print(ans)
