N,*T = list(map(int,input().split()))

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

ans = 3000



for x in range(4**N):

    l = [0]*4

    t = [0]*4

    n = 4

    i = 0



    for i in range(N):

        l[x%n] += L[i]

        t[x%n] += 1

        x//=n



    if 0 in l[:3]:

        continue

    cost = 0

    for i in range(3):

        cost += (t[i]-1)*10

        cost += abs(l[i]-T[i])

    ans = min(ans, cost)



print(ans)

from itertools import product



N,*T = list(map(int,input().split()))

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

ans = 3000



for x in product([0,1,2,3], repeat=N):

    cost = 0

    l = [0]*4

    for i,v in enumerate(x):

        l[v] += L[i]

        if v<3:

            cost += 10



    if 0 in l[:3]:

        continue

    cost -= 30

    for i in range(3):

        cost += abs(l[i]-T[i])

    ans = min(ans, cost)



print(ans)

N, *T = list(map(int, input().split()))
L = [int(eval(input())) for i in range(N)]
ans = 3000
for x in range(4**N):
    l = [0] * 4
    t = [0] * 4
    n = 4
    i = 0
    for i in range(N):
        l[x % n] += L[i]
        t[x % n] += 1
        x //= n
    if 0 in l[:3]:
        continue
    cost = 0
    for i in range(3):
        cost += (t[i] - 1) * 10
        cost += abs(l[i] - T[i])
    ans = min(ans, cost)
print(ans)

from itertools import product

N, *T = list(map(int, input().split()))
L = [int(eval(input())) for i in range(N)]
ans = 3000
for x in product([0, 1, 2, 3], repeat=N):
    cost = 0
    l = [0] * 4
    for i, v in enumerate(x):
        l[v] += L[i]
        if v < 3:
            cost += 10
    if 0 in l[:3]:
        continue
    cost -= 30
    for i in range(3):
        cost += abs(l[i] - T[i])
    ans = min(ans, cost)
print(ans)

+from itertools import product + -for x in range(4**N): +for x in product([0, 1, 2, 3], repeat=N): +    cost = 0 -    t = [0] * 4 -    n = 4 -    i = 0 -    for i in range(N): -        l[x % n] += L[i] -        t[x % n] += 1 -        x //= n +    for i, v in enumerate(x): +        l[v] += L[i] +        if v < 3: +            cost += 10 -    cost = 0 +    cost -= 30 -        cost += (t[i] - 1) * 10