n=int(input())
arr=list(map(int,input().split()))
i=0
j=-1
k=0
for i in range (n//2):
    k+=abs(arr[j]-arr[i])
    j-=1
    i+=1
print(k)