import sys
sys.stdin=open("CANDY.inp","r")
sys.stdout=open("CANDY.out","w")
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
if n<=20:
A=10**9
k=sum(a)
def đm(i,S):
global A,a
if i==n:
A=min(A,abs(S-(k-S)))
else:
đm(i+1,S)
đm(i+1,S+a[i])
đm(0,0)
print(A)
else:
B=0
C=0
for i in range(n):
if B>C:
C+=a[0]
a.pop(0)
else:
B+=a[0]
a.pop(0)
print(abs(B-C))
aW1wb3J0IHN5cwpzeXMuc3RkaW49b3BlbigiQ0FORFkuaW5wIiwiciIpCnN5cy5zdGRvdXQ9b3BlbigiQ0FORFkub3V0IiwidyIpCm49aW50KGlucHV0KCkpCmE9bGlzdChtYXAoaW50LGlucHV0KCkuc3BsaXQoKSkpCmEuc29ydChyZXZlcnNlPVRydWUpCmlmIG48PTIwOgogICAgQT0xMCoqOQogICAgaz1zdW0oYSkKICAgIGRlZiDEkW0oaSxTKToKICAgICAgICBnbG9iYWwgQSxhCiAgICAgICAgaWYgaT09bjogCiAgICAgICAgICAgIEE9bWluKEEsYWJzKFMtKGstUykpKQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIMSRbShpKzEsUykKICAgICAgICAgICAgxJFtKGkrMSxTK2FbaV0pCiAgICDEkW0oMCwwKQogICAgcHJpbnQoQSkKZWxzZToKICAgIEI9MAogICAgQz0wCiAgICBmb3IgaSBpbiByYW5nZShuKToKICAgICAgICBpZiBCPkM6CiAgICAgICAgICAgIEMrPWFbMF0KICAgICAgICAgICAgYS5wb3AoMCkKICAgICAgICBlbHNlOiAKICAgICAgICAgICAgQis9YVswXQogICAgICAgICAgICBhLnBvcCgwKQogICAgcHJpbnQoYWJzKEItQykpCg==