from itertools import product



def solve(NUM, LIST):

    lst = [l[i] for i, li in enumerate(LIST) if li == NUM]

    if len(lst) == 0:

        return 10 ** 5

    ANS = (len(lst) - 1) * 10

    ANS += abs(sum(lst) - target[NUM])

    return ANS



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

l = [int(eval(input())) for _ in range(target[0])]



ans = 10 ** 5

for pat in product([0, 1, 2, 3], repeat=target[0]):

    tmp = sum(solve(i + 1, pat) for i in range(3))

    ans = min(ans, tmp)

print(ans)

from itertools import product



def solve(NUM, LIST):

    lst = [l[i] for i, t in enumerate(LIST) if t == NUM]

    if len(lst) == 0:

        return 10 ** 5

    ANS = (len(lst) - 1) * 10

    ANS += abs(sum(lst) - tgt[NUM])

    return ANS



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

l = [int(eval(input())) for _ in range(tgt[0])]



ans = 10 ** 5

for pttn in product([0, 1, 2, 3], repeat=tgt[0]):

    tmp = sum(solve(i + 1, pttn) for i in range(3))

    ans = min(ans, tmp)

print(ans)

from itertools import product


def solve(NUM, LIST):
    lst = [l[i] for i, li in enumerate(LIST) if li == NUM]
    if len(lst) == 0:
        return 10**5
    ANS = (len(lst) - 1) * 10
    ANS += abs(sum(lst) - target[NUM])
    return ANS


target = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(target[0])]
ans = 10**5
for pat in product([0, 1, 2, 3], repeat=target[0]):
    tmp = sum(solve(i + 1, pat) for i in range(3))
    ans = min(ans, tmp)
print(ans)

from itertools import product


def solve(NUM, LIST):
    lst = [l[i] for i, t in enumerate(LIST) if t == NUM]
    if len(lst) == 0:
        return 10**5
    ANS = (len(lst) - 1) * 10
    ANS += abs(sum(lst) - tgt[NUM])
    return ANS


tgt = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(tgt[0])]
ans = 10**5
for pttn in product([0, 1, 2, 3], repeat=tgt[0]):
    tmp = sum(solve(i + 1, pttn) for i in range(3))
    ans = min(ans, tmp)
print(ans)

-    lst = [l[i] for i, li in enumerate(LIST) if li == NUM] +    lst = [l[i] for i, t in enumerate(LIST) if t == NUM] -    ANS += abs(sum(lst) - target[NUM]) +    ANS += abs(sum(lst) - tgt[NUM]) -target = list(map(int, input().split())) -l = [int(eval(input())) for _ in range(target[0])] +tgt = list(map(int, input().split())) +l = [int(eval(input())) for _ in range(tgt[0])] -for pat in product([0, 1, 2, 3], repeat=target[0]): -    tmp = sum(solve(i + 1, pat) for i in range(3)) +for pttn in product([0, 1, 2, 3], repeat=tgt[0]): +    tmp = sum(solve(i + 1, pttn) for i in range(3))