# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

import numpy as np
# from itertools import permutations
# from itertools import combinations
# from itertools import combinations_with_replacement

# import heapq
# from collections import deque

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    N = int(input())
    ps = map(int, input().split())

    sheets = np.ndarray(shape=(N, N), dtype=int)

    for i in range(N):
        rmax = min(i, N-1-i)
        sheets[i] = np.array([min(j, N-1-j, rmax) for j in range(N)])

    total = 0

    def update(x, y, v_new, sheets, parents):

        parents.add((x, y))
        v_old = sheets[x][y]

        if v_old != -1:
            sheets[x][y] = v_new

        v_update = max(v_new, v_old)

        positions = ((x-1, y), (x+1, y), (x, y-1), (x, y+1))

        for px, py in positions:
            if (px, py) in parents:
                continue

            if 0 <= px < N and 0 <= py < N:
                pv = sheets[px][py]
                if pv == -1:
                    update(px, py, v_update, sheets, parents)
                elif v_update < pv:
                    update(px, py, v_update, sheets, parents)

    for p in ps:
        px = (p-1) // N
        py = (p-1) % N

        pv = sheets[px][py]
        total += pv

        update(px, py, -1, sheets, set([]))

    return total


def main():
    print(solve())


if __name__ == "__main__":
    main()
