n = int(input())
p = list(map(int, input().split()))
s = [[0]*n for _ in range(n)]
ans = 0
def edge(N, i):
    if i % N == 0 or i % N == 1:
        return 1
    elif i > 1 and i <N:
        return 1
    elif i > N**2-N+1 and i<N**2:
        return 1
    else:
        return 0
    
def check(n, s, r, c):
    b =  1
    
    
    if not r ==0: #縦↑
        for j in range(r):
            if s[j][c]==0:
                b = 0
        if b==1:return 1
        else:b=1
        
    if not r == n-1: #縦↓
        for j in range(r+1, n):
            if s[j][c]==0:
                b = 0
        if b==1:return 1
        else:b=1
        
    if not c == 0: #横←
        for j in range(c):
            if s[r][j]==0:
                b = 0
        if b==1:return 1
        else:b=1
        
    if not c == n-1: #縦↓
        for j in range(c+1, n):
            if s[r][j]==0:
                b = 0
        if b==1:return 1  
    return 0


def mini(n, s, r, c):
    
    adisg = 10**100
    if not r ==0: #縦↑
        disg = 0
        for j in range(r):
            if s[j][c]==0:
                disg +=1
        adisg = min(adisg, disg)
        
    if not r == n-1: #縦↓
        disg = 0
        for j in range(r+1, n):
            if s[j][c]==0:
                disg +=1
        adisg = min(adisg, disg)
        
    if not c == 0: #横←
        disg = 0
        for j in range(c):
            if s[r][j]==0:
                disg +=1
        adisg = min(adisg, disg)
        
    if not c == n-1: #縦↓
        disg = 0
        for j in range(c+1, n):
            if s[r][j]==0:
                disg +=1
        adisg = min(adisg, disg)
    return adisg

for i in p:
    if i % n ==0:
        r = i//n-1
        c = n-1
    else:
        r = i//n
        c = i%n-1

    if edge(n, i):
        s[r][c] = 1
    
        continue
    elif check(n, s, r, c):
        s[r][c] = 1
      
        continue
    else:
        s[r][c] = 1
        ans += mini(n, s, r, c)
        
print(ans)