while 1:

	n = eval(input())

	if n == 0: break

	a = list(map(int,input().split()))

	s = sum(a)

	ref = [0]

	for i in a:

		ref += [i+j for j in ref if j < s/2]

	print(min(abs(s-2*i) for i in ref))
while 1:

	n = eval(input())

	if n == 0: break

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

	s = sum(a)

	L = [0]

	for i in a:

		L += [i+j for j in L if j < s/2]

	print(min(abs(s-2*i) for i in L))
while 1:
    n = eval(input())
    if n == 0:
        break
    a = list(map(int, input().split()))
    s = sum(a)
    ref = [0]
    for i in a:
        ref += [i + j for j in ref if j < s / 2]
    print(min(abs(s - 2 * i) for i in ref))

while 1:
    n = eval(input())
    if n == 0:
        break
    a = sorted(map(int, input().split()))[::-1]
    s = sum(a)
    L = [0]
    for i in a:
        L += [i + j for j in L if j < s / 2]
    print(min(abs(s - 2 * i) for i in L))

-    a = list(map(int, input().split())) +    a = sorted(map(int, input().split()))[::-1] -    ref = [0] +    L = [0] -        ref += [i + j for j in ref if j < s / 2] -    print(min(abs(s - 2 * i) for i in ref)) +        L += [i + j for j in L if j < s / 2] +    print(min(abs(s - 2 * i) for i in L))