n = gets.to_i
as = gets.split.map &:to_i

sum = as.inject(:+)

aa = []

start = 0
as.each{ |a|
	aa << start + a
	start += a
}

c_sum = sum / 2

x = aa.bsearch_index{ |a|
	a >= c_sum
}


if aa[x] == c_sum then
	puts 0
else
	puts [(sum - aa[x-1] * 2), (aa[x] * 2 - sum)].min
end
