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')





def calc(mask):

    cost = -30

    t = [0] * 3

    for j in range(n):

        idx = (mask >> (2 * j)) & 3

        if idx == 3: continue

        t[idx] += l[j]

        cost += 10



    if 0 in t[:3]:

        return inf



    cost += sum(abs(tt - gg) for tt, gg in zip(t, goal))

    return cost





def dfs(cur, mask):

    # l[cur]をa,b,c,未使用のいずれかにあてがう



    # base case

    if cur == n:

        return calc(mask)



    res = inf

    for i in range(4):

        # i == 0,1,2 : a,b,cにあてがう / i == 3 : 未使用

        res = min(res, dfs(cur + 1, mask | i << (2 * cur)))

    return res





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

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



print((dfs(0, 0)))

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")


def calc(mask):
    cost = -30
    t = [0] * 3
    for j in range(n):
        idx = (mask >> (2 * j)) & 3
        if idx == 3:
            continue
        t[idx] += l[j]
        cost += 10
    if 0 in t[:3]:
        return inf
    cost += sum(abs(tt - gg) for tt, gg in zip(t, goal))
    return cost


def dfs(cur, mask):
    # l[cur]をa,b,c,未使用のいずれかにあてがう
    # base case
    if cur == n:
        return calc(mask)
    res = inf
    for i in range(4):
        # i == 0,1,2 : a,b,cにあてがう / i == 3 : 未使用
        res = min(res, dfs(cur + 1, mask | i << (2 * cur)))
    return res


n, *goal = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
print((dfs(0, 0)))

-n, *goal = list(map(int, input().split())) -l = [int(eval(input())) for _ in range(n)] -ans = inf -for q in range(4**n): + + +def calc(mask): -        idx = (q // (4**j)) % 4 +        idx = (mask >> (2 * j)) & 3 -    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) +    if 0 in t[:3]: +        return inf +    cost += sum(abs(tt - gg) for tt, gg in zip(t, goal)) +    return cost + + +def dfs(cur, mask): +    # l[cur]をa,b,c,未使用のいずれかにあてがう +    # base case +    if cur == n: +        return calc(mask) +    res = inf +    for i in range(4): +        # i == 0,1,2 : a,b,cにあてがう / i == 3 : 未使用 +        res = min(res, dfs(cur + 1, mask | i << (2 * cur))) +    return res + + +n, *goal = list(map(int, input().split())) +l = [int(eval(input())) for _ in range(n)] +print((dfs(0, 0)))