n=int(input())
l=list(map(int,input().split()))
l1=l.copy()
a=0
for i in l:
    if(i%n==1 or i%n==0 or (i>=1 and i<=n) or (i>=n*n - n+1 and i<=n*n)):
        l1.remove(i)
    else:
        p=i%n
        q=n-i%n
        x=0
        for j in range(i+1,i+1+q):
            x+=l1.count(j)
        if(x==0):
            l1.remove(i)
            continue
        y=0
        for j in range(i-p+1,i):
            y+=l1.count(j)
        if(y==0):
            l1.remove(i)
            continue
        z=0
        for j in range(i%n,i+1,n):
            z+=l1.count(j)
        if(z==0):
            l1.remove(i)
            continue
        w=0
        for j in range(i+1,n*n-n+p+1,n):
            w+=l1.count(j)
        if(w==0):
            l1.remove(i)
            continue
        a+=min(x,y,z,w)
        l1.remove(i)
print(a)
