n = int(input())
l = list(map(int, input().split()))
j = n
l2 = []
y = 0
for i in range(len(l) - 1):
    while j > n//2 + 1:
        x =  abs(l[j - 1] - l[i])
        y = y + x
        j -=1
        break
print(y)