import queue
N = int(input())
aa = list(map(int, input().split()))


mm = [[0] * N for _ in range(N)]


for i in range((N + 1) // 2):
    j = N - i - 1

    for x in range(i, j + 1):
        mm[i][x] = i
        mm[j][x] = i
        mm[x][i] = i
        mm[x][j] = i


def pm():
    for m in mm:
        print(m)


is_none = [[False] * N for _ in range(N)]

ans = 0

for a in aa:
    x = (a - 1) % N
    y = (a - 1) // N

    # print(x, y)

    ans += mm[y][x]

    is_none[y][x] = True

    mm[y][x] -= 1

    q = queue.Queue()
    q.put((x, y, mm[y][x]))
    while not q.empty():
        x0, y0, n = q.get()

        xx = [x0, x0, x0 + 1, x0 - 1]
        yy = [y0 + 1, y0 - 1, y0, y0]
        for x, y in zip(xx, yy):
            if x < 0 or N <= x or y < 0 or N <= y:
                continue

            if is_none[y][x]:
                if mm[y][x] > n:
                    mm[y][x] = n
                    q.put((x, y, mm[y][x]))
            else:
                if mm[y][x] > n + 1:
                    mm[y][x] = n + 1
                    q.put((x, y, mm[y][x]))

    # pm()


print(ans)
