def S(i,x,y):

	d=2*max(x,y)-sum(a)

	return d if d>=0 else min(S(i+1,x+a[i],y),S(i+1,x,y+a[i]))

while 1:

	if eval(input())==0:break

	a=sorted(map(int,input().split()))[::-1]

	print(S(1,a[0],0))
def S(i,x,y):

	if 2*x >= A: return 2*x-A

	if 2*y >= A: return 2*y-A

	return min(S(i+1,x+a[i],y),S(i+1,x,y+a[i]))

while 1:

	n = eval(input())

	if n == 0: break

	a = sorted(map(int,input().split()))[::-1]

	A = sum(a)

	print(S(1,a[0],0))
def S(i, x, y):
    d = 2 * max(x, y) - sum(a)
    return d if d >= 0 else min(S(i + 1, x + a[i], y), S(i + 1, x, y + a[i]))


while 1:
    if eval(input()) == 0:
        break
    a = sorted(map(int, input().split()))[::-1]
    print(S(1, a[0], 0))

def S(i, x, y):
    if 2 * x >= A:
        return 2 * x - A
    if 2 * y >= A:
        return 2 * y - A
    return min(S(i + 1, x + a[i], y), S(i + 1, x, y + a[i]))


while 1:
    n = eval(input())
    if n == 0:
        break
    a = sorted(map(int, input().split()))[::-1]
    A = sum(a)
    print(S(1, a[0], 0))

-    d = 2 * max(x, y) - sum(a) -    return d if d >= 0 else min(S(i + 1, x + a[i], y), S(i + 1, x, y + a[i])) +    if 2 * x >= A: +        return 2 * x - A +    if 2 * y >= A: +        return 2 * y - A +    return min(S(i + 1, x + a[i], y), S(i + 1, x, y + a[i])) -    if eval(input()) == 0: +    n = eval(input()) +    if n == 0: +    A = sum(a)