n = gets.to_i
array = gets.split(" ").map(&:to_i)
result = array.inject(&:+)

(n - 1).times do |i|
  a = array.slice(0..i).inject(&:+)
  b = array.slice((i + 1)..(n - 1)).inject(&:+)
  result = (a - b).abs if result > (a - b).abs
end

puts result