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