def nsin(X,y):
    if(int(X/y)):
        return nsin(int(X/y),y)+str(X%y)
    return str(X%y)

cost=10000
for i in range(3**n):
    g=list(nsin(i,3).zfill(5))
    if len(set(g))!=3:
        continue
    la=[]
    lb=[]
    lc=[]
    for j in range(n):        
        if g[j]=="0":
            la.append(l[j])
        elif g[j]=="1":
            lb.append(l[j])
        elif g[j]=="2":
            lc.append(l[j])
    costa=10000
    costb=10000
    costc=10000
    for j in range(1,2**len(la)):
        ga=list(nsin(j,2).zfill(len(la)))
        A=0
        cont=-1
        for k in range(len(la)):
            if ga[k]=="1":
                A+=la[k]
                cont+=1
        tmp=cont*10+abs(A-a)
        if tmp<costa:
            costa=tmp
    for j in range(1,2**len(lb)):
        gb=list(nsin(j,2).zfill(len(lb)))
        B=0
        cont=-1
        for k in range(len(lb)):
            if gb[k]=="1":
                B+=lb[k]
                cont+=1
        tmp=cont*10+abs(B-b)
        if tmp<costb:
            costb=tmp
    for j in range(1,2**len(lc)):
        gc=list(nsin(j,2).zfill(len(lc)))
        C=0
        cont=-1
        for k in range(len(lc)):
            if gc[k]=="1":
                C+=lc[k]
                cont+=1
        tmp=cont*10+abs(C-c)
        if tmp<costc:
            costc=tmp
    if cost>(costa+costb+costc):
        cost=costa+costb+costc
print(cost)