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