N = int(input())
p_list = list(map(int, input().split()))

out_list = []

for i in range(N + 1):
    out_list.append(i + 1)

for i in range(N - 1):
    if N * N > N * (i + 2):
        out_list.append(N * (i + 2))
        out_list.append(N * (i + 2) + 1)

for i in range(N - 1):
    out_list.append(N * N - N + 1 + i + 1)

ans = []
ans_temp = []
temp = []
t = 0
for i in p_list:
    if i not in out_list:
        ip = i
        while ip not in out_list:
            t += 1
            ip += 1
            if ip in p_list[0:p_list.index(i)]:
                t += -1
        ans_temp.append(t)
        t = 0
        im = i
        while im not in out_list:
            t += 1
            im += -1
            if im in p_list[0:p_list.index(i)]:
                t += -1
        ans_temp.append(t)
        t = 0
        inm = i
        while inm not in out_list:
            t += 1
            inm += -N
            if inm in p_list[0:p_list.index(i)]:
                t += -1
        ans_temp.append(t)
        t = 0
        inp = i
        while inp not in out_list:
            t += 1
            inp += N
            if inp in p_list[0:p_list.index(i)]:
                t += -1
        ans_temp.append(t)
        t = 0
        ans.append(min(ans_temp))
        ans_temp.clear()
print(sum(ans))

