def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
import sys
sys.setrecursionlimit(10**6)
n=N()
p=L()
ans=[[0]*(n+1) for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,n+1):
        ans[i][j]=min(i-1,j-1,n-i,n-j)
c=[[1]*(n+1) for i in range(n+1)]
def f(x,y):
    for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
        if 1<=x+i<=n and 1<=y+j<=n:
            if ans[x][y]+c[x][y]<ans[x+i][y+j]:
                ans[x+i][y+j]-=1
                f(x+i,y+j)
t=0
for i in p:
    y=i%n
    if y==0:
        y=n
    x=(i+n-1)//n
    c[x][y]=0
    t+=ans[x][y]
    f(x,y)
print(t)