import sys
input = sys.stdin.readline
n = int(input())
p = list(map(int,input().split()))

grid = [[i for i in range(1+j,n+j+1)]for j in range(0,n**2,n)]
kumi = [[-1]*(n**2)for i in range(n**2)]
ans = 0
for i in range(len(p)):
    x = p[i]//n if p[i]%n != 0 else p[i]//n-1
    y = (p[i]-1)%n
    mad1 = 0
    mad1list = []
    mad2 = 0
    mad2list = []
    mad3 = 0
    mad3list = []
    mad4 = 0
    mad4list = []
    dx = 1
    while x+dx <= n-1:
        if grid[x+dx][y] != '#':
            mad1 += 1
            mad1list.append(grid[x+dx][y])
        dx += 1

    dx = -1
    while x + dx >= 0:
        if grid[x + dx][y] != '#':
            mad2 += 1
            mad2list.append(grid[x + dx][y])
        dx -= 1
    dy = 1
    while y + dy <= n-1:
        if grid[x][y+dy] != '#':
            mad3 += 1
            mad3list.append(grid[x][y+dy])
        dy += 1
            
    dy = -1
    while y + dy >= 0:
        if grid[x][y+dy] != '#':
            mad4 += 1
            mad4list.append(grid[x][y+dy])
        dy -= 1
    if min(mad1,mad2,mad3,mad4) != 0:
        if mad1 == min(mad1,mad2,mad3,mad4):
            for m in mad1list:
                if kumi[grid[x][y]-1][m-1] != 0:
                    ans += 1
                    kumi[grid[x][y]-1][m-1] = 0
        elif mad2 == min(mad1,mad2,mad3,mad4):
            for m in mad2list:
                if kumi[grid[x][y]-1][m-1] != 0:
                    ans += 1
                    kumi[grid[x][y]-1][m-1] = 0
        elif mad3 == min(mad1,mad2,mad3,mad4):
            for m in mad3list:
                if kumi[grid[x][y]-1][m-1] != 0:
                    ans += 1
                    kumi[grid[x][y]-1][m-1] = 0
        else:
            for m in mad4list:
                if kumi[grid[x][y]-1][m-1] != 0:
                    ans += 1
                    kumi[grid[x][y]-1][m-1] = 0
        #madlist.append(p[i])
    grid[x][y] = '#'
print(ans)
#print(madlist)