n = int(input())
orderstring = input()
ordercopy = orderstring.split(" ")
order = [0]*n
index = 0
while index < n:
    order[index] = int(ordercopy[index])
seat = [["occupied" for i in range(n)] for j in range(n)]
hated = 0
i = 0
while i < len(order):
    col = order[i] % n - 1
    row = (order[i] - col) / n - 1
    area = [["no" for i in range(n)] for j in range(n)]
    area[row][col] = "yes"
    times = 0
    judge = 0
    while times < 500:
        r = 0
        c = 0
        while 0 < r and r < n - 1:
            while 0 < c and c < n - 1:
                if area[r][c] == "yes" and seat[r-1][c]=="empty":
                    area[r-1][c] = "yes"
                if area[r][c] == "yes" and seat[r][c-1]=="empty":
                    area[r][c-1] = "yes"
                if area[r][c] == "yes" and seat[r+1][c]=="empty":
                    area[r+1][c] = "yes"
                if area[r][c] == "yes" and seat[r][c+1]=="empty":
                    area[r][c+1] = "yes"
                c+= 1
            r+=1
        times+=1
    test = 0
    while test < n:
        if area[0][test] == "yes":
            judge = 1
        test+=1
    test = 0
    while test < n:
        if area[n-1][test] == "yes":
            judge = 1
        test+=1
    test = 0
    while test < n:
        if area[test][0] == "yes":
            judge = 1
        test+=1
    while test < n:
        if area[test][n-1] == "yes":
            judge = 1
        test+=1
    if judge == 0:
        hated+=1
    i+=1
print(hated)