size = int(input())

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

i = 0

numbers_of_ammo = 0

while i < len(L) // 2:
    if L[i] > L[len(L) - 1 - i]:
        numbers_of_ammo += L[i] - L[len(L) - 1 - i]
    else:
        numbers_of_ammo += L[len(L) - 1 - i] - L[i]

    i += 1


print(numbers_of_ammo)