import sys
import math
import itertools
import collections
import numpy as np

rl = sys.stdin.readline
n = int(rl())
dp = np.full((n, n), 500)
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
def m(x, y):
    global mi
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if nx < 0 or ny < 0 or nx >= n or ny >= n or dp[nx][ny] == 0:
            dp[x][y] = 0
            break
        else:
            if dp[nx][ny] == 500:
                if x >= n/2:
                    tempx = n-x-1
                    if y >= n/2:
                        tempy = n-y-1
                        if tempx > tempy:
                            temp = tempy
                        else:
                            temp = tempx
                    else:
                        tempy = y
                        if tempx > tempy:
                            temp = tempy
                        else:
                            temp = tempx
                else:
                    tempx = x
                    if y >= n/2:
                        tempy = n-y-1
                        if tempx > tempy:
                            temp = tempy
                        else:
                            temp = tempx
                    else:
                        tempy = y
                        if tempx > tempy:
                            temp = tempy
                        else:
                            temp = tempx
                if temp < mi:
                    mi = temp
            elif dp[x][y] != mi:
                m(nx, ny)
            elif dp[nx][ny] < mi:
                mi = dp[nx][ny]
            dp[x][y] = mi
for nu in list(map(int, rl().split())):
    x1 = (nu-1)%n
    y1 = (nu-1)//n
    mi = 500
    m(x1, y1)
print(sum(sum(dp))-(n-3))
            
