
n= int(input())
a= list(map(int,input().split()))

b = [0]*n
after = [-1]*n

print(b)
for num,i in enumerate(a):
    b[i-1]=num

for j in range(0,n,-1):
    top = 0
    tail = n
    while True:
        if j-top > tail - j:
            if after[top] == -1:
                after[top] ==j-top
                break
            else:
                top+= 1
        else:
            if after[tail] == -1:
                after[tail] ==tail-j
                break
            else:
                tail-= 1

print(sum(after))