inf = float('inf')



n, *goal = list(map(int, input().split()))

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



ans = inf

for q in range(4 ** n):

    m = [[] for _ in range(4)]

    lm = 0

    for j in range(n):

        idx = (q // (4 ** j)) % 4

        m[idx].append(l[j])

    if any(len(m[idx]) == 0 for idx in range(3)):

        continue



    cost = 0

    for idx in range(3):

        merge_time = len(m[idx]) - 1

        cost += merge_time * 10

        cost += abs(sum(m[idx]) - goal[idx])



    ans = min(ans, cost)



print(ans)

inf = float('inf')



n, *goal = list(map(int, input().split()))

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



ans = inf

for q in range(4 ** n):

    cost = -30

    t = [0] * 3

    for j in range(n):

        idx = (q // (4 ** j)) % 4

        if idx == 3: continue

        t[idx] += l[j]

        cost += 10



    if any(tt == 0 for tt in t):

        continue



    for idx in range(3):

        cost += abs(t[idx] - goal[idx])



    ans = min(ans, cost)



print(ans)

inf = float("inf")
n, *goal = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
ans = inf
for q in range(4**n):
    m = [[] for _ in range(4)]
    lm = 0
    for j in range(n):
        idx = (q // (4**j)) % 4
        m[idx].append(l[j])
    if any(len(m[idx]) == 0 for idx in range(3)):
        continue
    cost = 0
    for idx in range(3):
        merge_time = len(m[idx]) - 1
        cost += merge_time * 10
        cost += abs(sum(m[idx]) - goal[idx])
    ans = min(ans, cost)
print(ans)

inf = float("inf")
n, *goal = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
ans = inf
for q in range(4**n):
    cost = -30
    t = [0] * 3
    for j in range(n):
        idx = (q // (4**j)) % 4
        if idx == 3:
            continue
        t[idx] += l[j]
        cost += 10
    if any(tt == 0 for tt in t):
        continue
    for idx in range(3):
        cost += abs(t[idx] - goal[idx])
    ans = min(ans, cost)
print(ans)

-    m = [[] for _ in range(4)] -    lm = 0 +    cost = -30 +    t = [0] * 3 -        m[idx].append(l[j]) -    if any(len(m[idx]) == 0 for idx in range(3)): +        if idx == 3: +            continue +        t[idx] += l[j] +        cost += 10 +    if any(tt == 0 for tt in t): -    cost = 0 -        merge_time = len(m[idx]) - 1 -        cost += merge_time * 10 -        cost += abs(sum(m[idx]) - goal[idx]) +        cost += abs(t[idx] - goal[idx])