n = int(input())

L = list(map(int, input().split()))

ans = 0


for i in range(n // 2):

    ans += abs( L[i] - L[n - 1 - i] )

print(ans)