n = gets.to_i
w = gets.split.map(&:to_i)

left = [w.first]
1.upto(n - 2).each {|i|
    left.push(left.last + w[i])
}

right = [w.last]
(n - 2).downto(1).each {|i|
    right.push(right.last + w[i])
}
right.reverse!

min = (left[0] - right[0]).abs
1.upto(n - 2).each {|i|
    abs = (left[i] - right[i]).abs
    if abs < min then
        min = abs
    end
}

puts min
