a = int(input())
x = [int(x) for x in input().split()]
a = len(x) // 2
bullet = 0
if len(x) % 2 != 0:
if sum(x[:a]) > sum(x[a+1:]):
for i in range (len(x[:a])):
b = x[:a][i] - x[a+1:][i]
bullet += b
elif sum(x[a+1:]) > sum(x[:a]):
for i in range(len(x[a+1:])):
b = x[a+1:][i] - x[:a][i]
bullet += b
elif sum(x[a+1:]) > sum(x[:a]):
bullet += 0
else:
if sum(x[:a]) > sum(x[a:]):
for i in range (len(x[:a])):
b = x[:a][i] - x[a:][i]
bullet += b
elif sum(x[a:]) > sum(x[:a]):
for i in range(len(x[:a])):
b = x[a:][i] - x[:a][i]
bullet += b
else:
bullet += 0
print(bullet)