class Q1045
  def min a,b
    return a < b ? a : b
  end
  
  def getMin ary, a, b, i, n
    if(i == n)
      return (a - b).abs
    else
      return min((getMin ary, a + ary[i], b, i+1, n), (getMin ary, a, b + ary[i], i+1, n))
    end
  end
  def doIt
    n = gets.to_i
    while n > 0
      ary = gets.split(" ").map{|x| x.to_i}
      puts (getMin ary, 0, 0, 0, n)
      n = gets.to_i
    end
  end
end

Q1045.new.doIt