N = gets.to_i
weight_arr = gets.split(" ").map(&:to_i)

s1 = 0
s2 = weight_arr.sum
diff = s2

weight_arr.each do |w|
  s1 += w
  s2 -= w
  c_diff = (s1 - s2).abs

  diff = c_diff if diff > c_diff
  # 差が増加する場合は以降の計算は不要
  break if diff - c_diff < 0
end
puts diff
