def kousin(klist, koho):
    koho2=[]
    for kh in koho:
        tate=kh[0]
        yoko=kh[1]
        tesu=kh[2]
        #RIGHT, LEFT, UP,DOWN
        if clist[tate][yoko]==0:
            if tate==0:
                koho2.append([tate+1, yoko, tesu])
                if yoko==0:
                    koho2.append([tate, yoko+1, tesu])
                elif yoko==n-1:
                    koho2.append([tate, yoko-1, tesu])
                else:
                    koho2.append([tate, yoko+1, tesu])
                    koho2.append([tate, yoko-1, tesu])
            elif tate==n-1:
                koho2.append([tate-1, yoko, tesu])
                if yoko==0:
                    koho2.append([tate, yoko+1, tesu])
                elif yoko==n-1:
                    koho2.append([tate, yoko-1, tesu])
                else:
                    koho2.append([tate, yoko+1, tesu])
                    koho2.append([tate, yoko-1, tesu])
            else:
                koho2.append([tate-1, yoko, tesu])
                koho2.append([tate+1, yoko, tesu])
                if yoko==0:
                    koho2.append([tate, yoko+1, tesu])
                elif yoko==n-1:
                    koho2.append([tate, yoko-1, tesu])
                else:
                    koho2.append([tate, yoko+1, tesu])
                    koho2.append([tate, yoko-1, tesu])
        
        else:
            if tate==0:
                koho2.append([tate+1, yoko, tesu+1])
                if yoko==0:
                    koho2.append([tate, yoko+1, tesu+1])
                elif yoko==n-1:
                    koho2.append([tate, yoko-1, tesu+1])
                else:
                    koho2.append([tate, yoko+1, tesu+1])
                    koho2.append([tate, yoko-1, tesu+1])
            elif tate==n-1:
                koho2.append([tate-1, yoko, tesu+1])
                if yoko==0:
                    koho2.append([tate, yoko+1, tesu+1])
                elif yoko==n-1:
                    koho2.append([tate, yoko-1, tesu+1])
                else:
                    koho2.append([tate, yoko+1, tesu+1])
                    koho2.append([tate, yoko-1, tesu+1])
            else:
                koho2.append([tate-1, yoko, tesu+1])
                koho2.append([tate+1, yoko, tesu+1])
                if yoko==0:
                    koho2.append([tate, yoko+1, tesu+1])
                elif yoko==n-1:
                    koho2.append([tate, yoko-1, tesu+1])
                else:
                    koho2.append([tate, yoko+1, tesu+1])
                    koho2.append([tate, yoko-1, tesu+1])
    koho3=[]
    for kh2 in koho2:
        tate=kh2[0]
        yoko=kh2[1]
        tesu=kh2[2]
        if klist[tate][yoko]==tesu+1:
            klist[tate][yoko]=tesu
            koho3.append([tate, yoko, tesu])
        
    koho=koho3
    
    if koho!=[]:
        kousin(klist, koho)
    

n=int(input())
klist=[]
clist=[]

for i in range(n):
    now=[]
    if i<(n+1)//2:
        for j in range(i):
            now.append(j)
        now+=[i]*(n-i*2)
        #print("!")
        for j in range(i):
            now.append(i-j-1)
    else:
        for j in range(n-i):
            now.append(j)
        now+=[n-i-1]*(i*2-n)
        for j in range(n-i):
            now.append(n-i-j-1)
    klist.append(now)
    clist.append([1]*n)

answer=0

plist = list(map(int, input().split()))
for pl in plist:
    now1=(pl-1)//n
    now2=(pl-1)%n
    answer+=klist[now1][now2]
    clist[now1][now2]=0
    kousin(klist, [ [now1, now2, klist[now1][now2]] ])
    """
    print(pl, answer)
    view(clist)
    print(",")
    view(klist)
    print(".")
    """

print(answer)