from collections import deque

def leave(n, L):
    
    hasleft = [0 for i in range(n*n+1)]
    hates = 0
    
    def bfs(k):
        visited = [0 for i in range(n*n+1)]
        deq = deque()
        deq.append((0, k))
        while True:
            t = deq.popleft()
            if t[1] > n*n-n or t[1] <= n or t[1] % n == 1 or t[1] % n == 0:
                return t[0]
            for x in (n, -n, 1, -1):
                if not visited[t[1] + x]:
                    if hasleft[t[1] + x]:
                        deq.appendleft((t[0], t[1] + x))
                    else:
                        deq.append((t[0] + 1, t[1] + x))
            visited[t[1]] = 1
                    
    for k in L:
        hates += bfs(k)
        hasleft[k] = 1
    
    return hates

  
n = int(input())
L = [int(s) for s in input().split()]
print(leave(n, L))

