@n = gets.to_i
@w_array = gets.chomp.split(' ').map(&:to_i)

def diff(k)
    former = @w_array.first(k).inject(:+)
    latter = @w_array.last(@n - k).inject(:+)
    (latter - former).abs
end

diff_array = []

1.upto(@n - 1) do |i|
    diff_array << diff(i)
end

print diff_array.min