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





def calc(mask):

    t = [0] * 3

    cnt = 0

    for j in range(n):

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

        if idx == 3:

            cnt += 1

            continue

        t[idx] += l[j]



    if 0 in t:

        return inf



    return sum(abs(tt - gg) for tt, gg in zip(t, goal)) + (n - cnt - 3) * 10





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


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


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


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

-    cost = -30 +    cnt = 0 +            cnt += 1 -        cost += 10 -    if 0 in t[:3]: +    if 0 in t: -    cost += sum(abs(tt - gg) for tt, gg in zip(t, goal)) -    return cost +    return sum(abs(tt - gg) for tt, gg in zip(t, goal)) + (n - cnt - 3) * 10