def DFS(m,n,x,y,f,th):
    # print(x,y,th)
    if x in(0,n-1) or y in(0,n-1):
        return th

    r = (x+1)%n
    l = (x-1)%n
    t = (y+1)%n
    b = (y+1)%n
    flg = 999999999999
    if m[y][r] == 0 and f != 'l':
        flg = min(DFS(m,n,r,y,'r',th),flg)
    elif m[y][r] == 1 and f != 'l':
        flg = min(flg,DFS(m,n,r,y,'r',th+1))
    if m[y][l] == 0  and f != 'r':
        flg = min(flg,DFS (m,n,l,y,'l',th))
    elif m[y][l] == 1  and f != 'r':
        flg = min(flg,DFS (m,n,l,y,'l',th+1))
    if m[t][x] == 0 and f != 'b':
        flg = min(flg,DFS(m,n,x,t,'b',th))
    elif m[t][x] == 1 and f != 'b':
        flg = min(flg,DFS(m,n,x,t,'b',th+1))
    if m[b][x] == 0 and f != 't': 
        flg = min(flg,DFS(m,n,x,b,'t',th))
    elif m[b][x] == 1 and f != 't':
        flg = min(DFS(m,n,x,b,'t',th+1),flg)
    return flg



n = int(input())
p = [int(i)-1 for i in input().split()]
# print(p)


m = [[1] * n for i in range(n)]
# print(m)
c = 0
for i in p:
    x = i%n
    y = -(-(i+1)//n)-1 
    m[y][x] = 0
    c += (DFS(m,n,x,y,'',0))
    # print('aa',i+1,c)
        
    
print(c)


