n = int(input())
numbers = list(map(int, input().split()))
l = int((n - 1) // 2)
ans = 0
for i in range(0, l+1):
    if numbers[i] >= numbers[-1-i]:
        ans += numbers[i] - numbers[-1-i]
    else:
        ans += numbers[-1 - i] - numbers[i]
print(ans)