N = int(input())
P = list(map(int, input().split()))
T = [1] * (N*N)

m = 0
for i in range(len(P)):
    hate = 0
    T[P[i]-1] = 0
    if P[i] % N == 0 or P[i] % N == 1:
        hate = 0
    else:
        now = P[i]
        tate_up = now//N
        tate_down = N-now//N-1
        tate = min(tate_up, tate_down)
        yoko_r = (now//N+1)*N-now
        yoko_l = now-(now//N)*N+1
        yoko = min(yoko_r, yoko_l)

        if tate_up < tate_down:
            for j in range(tate):
                if T[now-N*j-1] == 1:
                    hate += 1
        else:
            for j in range(tate):
                if T[now+N*j-1] == 1:
                    hate += 1
        if yoko_r < yoko_l:
            for k in range(yoko):
                if T[now+k] == 1:
                    hate += 1
        else:
            for k in range(yoko):
                if T[now-k] == 1:
                    hate += 1
    if hate > m:
        m = hate
print(m)