def solve(l, lmt)
  m = (0..1).map{ Array.new(lmt+1, 0) }
  for v in l
    for j in 0..lmt
      m[1][j] = (j >= v ? [m[0][j-v] + v, m[0][j]].max : m[0][j])
    end
    m.rotate!
  end
  m[0][-1]
end
while n = gets.to_i
  break if n == 0
  l = gets.split.map(&:to_i)
  sum = l.reduce(:+)
  p sum - 2 * solve(l, sum/2)
end