def resolve(N,Ps):
    seats = dict()
    rev = dict()
    for i in range(N):
        for j in range(N):
            no = i*N + j+1
            seats[(i+1, j+1)] = i*N + j+1
            rev[no] = (i+1, j+1)

    dislike = set()


    def leave(p):
        nonlocal seats
        i, j = rev[p]
        seats[(i,j)] = 0


        ue  = [(ii, j) for ii in range(1, i)]
        shita  = [(ii, j) for ii in range(i+1, N+1)]
        hidari  = [(i, jj) for jj in range(1, j)]
        migi  = [(i, jj) for jj in range(j+1, N+1)]

        #print(f"({i},{j}) ue {ue}")
        #print(f"({i},{j}) shita {shita}")
        #print(f"({i},{j}) hidari {hidari}")
        #print(f"({i},{j}) migi {migi}")

        houkous = [ue, shita, hidari, migi]

        houkou = min(houkous, key=lambda houkou: len([index for index in houkou if seats[index] != 0]))

        pairs = set((p, seats[index]) for index in houkou if seats[index] != 0)

        return pairs
    
    for p in Ps:
        pairs = leave(p)
        dislike |= pairs
        
    return dislike


def main():
    N = int(input())
    Ps = list(map(int, input().split()))
    ans = resolve(N, Ps)

    print(len(ans))

if __name__ == '__main__':
    main()