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

sum = 0
ws.each { |i| sum += i }

mae = 0
abs = sum
tmp = sum

ws.each do |i|
  mae += i
  sum -= i
  tmp = (mae-sum).abs
  abs = tmp if tmp < abs
end

puts abs