def count(height):
N = len(height)
left = height[:N // 2]
right = height[N // 2:][::-1]
bullets = 0
for i in range(N // 2):
if right[i] > left[i]:
bullets += right[i] - left[i]
right[i] = left[i]
return bullets
n = int(input())
heights = list(map(int, input().split()))
minimum = count(heights)
print(minimum)