n = int(input())
p = list(map(int,input().split()))

thtr = [0]*((n+2)**2)
tpsn = [0]*((n+2)**2)
psn = [1]*(n**2)

def ppidx(ttidx):
    r = ttidx // (n+2) - 1
    c = ttidx % (n+2) - 1
    if r == 0 or r >= n:
        return -1
    if c== 0 or c >= n:
        return -1
    return n*r + c

def ttidx(psidx):
    r = psidx // n
    c = psidx %  n
    return (n+2)*(r+1) + c + 1

def init_rnk(psidx):
    r = psidx // n
    c = psidx %  n
    return(min(r,c,n-1-r,n-1-c)+1)

def get_cst(tidx,h):
    if thtr[tidx]==0:
        return 0

    if tidx in h:
        return 99

    h.add(tidx)

    wk = min( get_cst(tidx-1,h)   + tpsn[tidx-1]\
             ,get_cst(tidx+1,h)   + tpsn[tidx+1]\
             ,get_cst(tidx-n-2,h) + tpsn[tidx-n-2]\
             ,get_cst(tidx+n+2,h) + tpsn[tidx+n+2])

    if wk == 0:
        thtr[tidx] = 0

    return wk

#初期化
for i in range(n**2):
    tpsn[ttidx(i)] = 1
    thtr[ttidx(i)] = 1

#処理
ans = 0
for el in p:
    psn[el-1]=0
    tpsn[ttidx(el-1)]=0
    h = set()
    wk = get_cst(ttidx(el-1),h)
    ans += wk

print(ans)
