from itertools import product

N,A,B,C = list(map(int,input().split()))

L = [int(eval(input())) for _ in range(N)]

cntmin = abs(A-L[0])+abs(B-L[1])+abs(C-L[2])

for x in product(list(range(4)),repeat=N):

    cnt = 0

    a = x.count(1)

    b = x.count(2)

    c = x.count(3)

    if a*b*c==0:continue

    A1 = []

    B1 = []

    C1 = []

    for i in range(N):

        if x[i]==1:

            A1.append(L[i])

        elif x[i]==2:

            B1.append(L[i])

        elif x[i]==3:

            C1.append(L[i])

    cntA = 10*(len(A1)-1)

    La = 0

    for l in A1:

        La += l

    cntA += abs(A-La)

    cntB = 10*(len(B1)-1)

    Lb = 0

    for l in B1:

        Lb += l

    cntB += abs(B-Lb)

    cntC = 10*(len(C1)-1)

    Lc = 0

    for l in C1:

        Lc += l

    cntC += abs(C-Lc)

    cntmin = min(cntmin,cntA+cntB+cntC)

        

print(cntmin)    
from itertools import permutations,product

N,A,B,C = list(map(int,input().split()))

L = [int(eval(input())) for _ in range(N)]

G = {0:[],1:[],2:[]}

cmin = 10**5

for x in permutations(list(range(N)),3):

    for y in product(list(range(4)),repeat=N-3):

        G[0] = [x[0]]

        G[1] = [x[1]]

        G[2] = [x[2]]

        G[3] = []

        Ind = list(range(N))

        Ind.remove(x[0])

        Ind.remove(x[1])

        Ind.remove(x[2])

        for i in range(N-3):

            G[y[i]].append(Ind[i])

        cA = 0

        nA = len(G[0])

        cA = (nA-1)*10

        xA = 0

        for j in range(nA):

            xA += L[G[0][j]]

        cA += abs(A-xA)

        cB = 0

        nB = len(G[1])

        cB = (nB-1)*10

        xB = 0

        for j in range(nB):

            xB += L[G[1][j]]

        cB += abs(B-xB)

        cC = 0

        nC = len(G[2])

        cC = (nC-1)*10

        xC = 0

        for j in range(nC):

            xC += L[G[2][j]]

        cC += abs(C-xC)

        cmin = min(cmin,cA+cB+cC)

print(cmin)
from itertools import product

N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
cntmin = abs(A - L[0]) + abs(B - L[1]) + abs(C - L[2])
for x in product(list(range(4)), repeat=N):
    cnt = 0
    a = x.count(1)
    b = x.count(2)
    c = x.count(3)
    if a * b * c == 0:
        continue
    A1 = []
    B1 = []
    C1 = []
    for i in range(N):
        if x[i] == 1:
            A1.append(L[i])
        elif x[i] == 2:
            B1.append(L[i])
        elif x[i] == 3:
            C1.append(L[i])
    cntA = 10 * (len(A1) - 1)
    La = 0
    for l in A1:
        La += l
    cntA += abs(A - La)
    cntB = 10 * (len(B1) - 1)
    Lb = 0
    for l in B1:
        Lb += l
    cntB += abs(B - Lb)
    cntC = 10 * (len(C1) - 1)
    Lc = 0
    for l in C1:
        Lc += l
    cntC += abs(C - Lc)
    cntmin = min(cntmin, cntA + cntB + cntC)
print(cntmin)

from itertools import permutations, product

N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
G = {0: [], 1: [], 2: []}
cmin = 10**5
for x in permutations(list(range(N)), 3):
    for y in product(list(range(4)), repeat=N - 3):
        G[0] = [x[0]]
        G[1] = [x[1]]
        G[2] = [x[2]]
        G[3] = []
        Ind = list(range(N))
        Ind.remove(x[0])
        Ind.remove(x[1])
        Ind.remove(x[2])
        for i in range(N - 3):
            G[y[i]].append(Ind[i])
        cA = 0
        nA = len(G[0])
        cA = (nA - 1) * 10
        xA = 0
        for j in range(nA):
            xA += L[G[0][j]]
        cA += abs(A - xA)
        cB = 0
        nB = len(G[1])
        cB = (nB - 1) * 10
        xB = 0
        for j in range(nB):
            xB += L[G[1][j]]
        cB += abs(B - xB)
        cC = 0
        nC = len(G[2])
        cC = (nC - 1) * 10
        xC = 0
        for j in range(nC):
            xC += L[G[2][j]]
        cC += abs(C - xC)
        cmin = min(cmin, cA + cB + cC)
print(cmin)

-from itertools import product +from itertools import permutations, product -cntmin = abs(A - L[0]) + abs(B - L[1]) + abs(C - L[2]) -for x in product(list(range(4)), repeat=N): -    cnt = 0 -    a = x.count(1) -    b = x.count(2) -    c = x.count(3) -    if a * b * c == 0: -        continue -    A1 = [] -    B1 = [] -    C1 = [] -    for i in range(N): -        if x[i] == 1: -            A1.append(L[i]) -        elif x[i] == 2: -            B1.append(L[i]) -        elif x[i] == 3: -            C1.append(L[i]) -    cntA = 10 * (len(A1) - 1) -    La = 0 -    for l in A1: -        La += l -    cntA += abs(A - La) -    cntB = 10 * (len(B1) - 1) -    Lb = 0 -    for l in B1: -        Lb += l -    cntB += abs(B - Lb) -    cntC = 10 * (len(C1) - 1) -    Lc = 0 -    for l in C1: -        Lc += l -    cntC += abs(C - Lc) -    cntmin = min(cntmin, cntA + cntB + cntC) -print(cntmin) +G = {0: [], 1: [], 2: []} +cmin = 10**5 +for x in permutations(list(range(N)), 3): +    for y in product(list(range(4)), repeat=N - 3): +        G[0] = [x[0]] +        G[1] = [x[1]] +        G[2] = [x[2]] +        G[3] = [] +        Ind = list(range(N)) +        Ind.remove(x[0]) +        Ind.remove(x[1]) +        Ind.remove(x[2]) +        for i in range(N - 3): +            G[y[i]].append(Ind[i]) +        cA = 0 +        nA = len(G[0]) +        cA = (nA - 1) * 10 +        xA = 0 +        for j in range(nA): +            xA += L[G[0][j]] +        cA += abs(A - xA) +        cB = 0 +        nB = len(G[1]) +        cB = (nB - 1) * 10 +        xB = 0 +        for j in range(nB): +            xB += L[G[1][j]] +        cB += abs(B - xB) +        cC = 0 +        nC = len(G[2]) +        cC = (nC - 1) * 10 +        xC = 0 +        for j in range(nC): +            xC += L[G[2][j]] +        cC += abs(C - xC) +        cmin = min(cmin, cA + cB + cC) +print(cmin)