n = gets.chomp.to_i
ary = gets.chomp.split(" ").map(&:to_i)

t = (ary.size/2.to_f).ceil

res1 = []
res2 = []

ary.each_with_index do |v, k|
  if k + 1 <= t
    res1 << v
  else
    res2 << v
  end
end

res = 0
if res1.sum > res2.sum
  res = res1.sum - res2.sum
else
  res = res2.sum - res1.sum
end

t2 = t - 1
loop do
  if res >= ary[t2]
    res = res - ary[t2] * 2
  else
    break
  end
  t2 -= 1
end
puts res
