loop do
  n =gets.to_i
  break if n==0
  if n==1
    puts  gets.to_i
    next
  end
  ps = gets.split.map(&:to_i)
  sum = ps.inject{|a,b| a+b}
  ans = ps.combination(n/2).to_a.map { |x|
    tmp = x.reduce(:+)
    (sum-2*tmp).abs
  }.min
  puts ans
end