import collections

N=int(input())
list = list(map(int, input().split()))
blist=[]
z=1
while(z<=N**2):
  blist.append(int(z))
  z+=1

def check(num):
  if(num<=N):
    return 0
  elif(N**2-N+1 <= num <= N**2):
    return 0
  elif(num % N==0):
    return 0
  elif(num % N==1):
    return 0
  else:
    i=1
    tmp1=0
    c=collections.Counter(blist)
    while(i<=N):
      if(c[num-N*i]!=0):
        tmp1+=1
      i+=1
    j=1
    tmp2=0
    while(j<=N):
      if(c[num+N*j]!=0):
        tmp2+=1
      j+=1
    tmp3=0
    p=num
    while(p % N !=0):
      p=p+1
      if(c[p]!=0):
        tmp3+=1
    tmp4=0
    q=num
    while(q % N !=1):
      q=q-1
      if(c[q]!=0):
        tmp4+=1
    if(tmp1==0 or tmp2==0 or tmp3==0 or tmp4==0):
      return 0
    else:
      tmplist=[]
      tmplist.append(tmp1)
      tmplist.append(tmp2)
      tmplist.append(tmp3)
      tmplist.append(tmp4)
      at=min(tmplist)
      return(at)
k=0
res=0
l=len(list)

while(k<l):
  a=list[k]
  blist.remove(a)
  if(check(a)!=0):
    res+=check(a)
  k+=1

print(res)
