import itertools





n_bamboo, b1, b2, b3 = [int(i) for i in input().split()]

bamboos = [int(eval(input())) for _ in range(n_bamboo)]



ans = float("inf")

# すべての竹について、b1, b2, b3のどの竹に使うかを列挙

# 0のときはどの竹にも使わない

for bit in itertools.product((0, 1, 2, 3), repeat=n_bamboo):

    l1, l2, l3 = 0, 0, 0

    c1, c2, c3 = 0, 0, 0

    # 選択した竹を足す（2つ目以降はMP10消費）

    for b, bamboo in zip(bit, bamboos):

        if b == 1:

            if l1 > 0:

                c1 += 10

            l1 += bamboo

        elif b == 2:

            if l2 > 0:

                c2 += 10

            l2 += bamboo

        elif b == 3:

            if l3 > 0:

                c3 += 10

            l3 += bamboo

    # 1つも構成する竹がない竹がある場合はスキップ

    if l1 * l2 * l3 == 0:

        continue

    # 延長、短縮のコスト

    c1 += abs(b1 - l1)

    c2 += abs(b2 - l2)

    c3 += abs(b3 - l3)

    # 合計コストが今までより低ければ更新

    ans = min(ans, c1 + c2 + c3)

print(ans)

def dfs(cursor, a, b, c):

    if cursor == N:

        return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else float("inf")

    ret0 = dfs(cursor + 1, a, b, c)

    ret1 = dfs(cursor + 1, a + l[cursor], b, c) + 10

    ret2 = dfs(cursor + 1, a, b + l[cursor], c) + 10

    ret3 = dfs(cursor + 1, a, b, c + l[cursor]) + 10

    return min(ret0, ret1, ret2, ret3)





N, A, B, C = [int(i) for i in input().split()]

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

print((dfs(0, 0, 0, 0)))

import itertools

n_bamboo, b1, b2, b3 = [int(i) for i in input().split()]
bamboos = [int(eval(input())) for _ in range(n_bamboo)]
ans = float("inf")
# すべての竹について、b1, b2, b3のどの竹に使うかを列挙
# 0のときはどの竹にも使わない
for bit in itertools.product((0, 1, 2, 3), repeat=n_bamboo):
    l1, l2, l3 = 0, 0, 0
    c1, c2, c3 = 0, 0, 0
    # 選択した竹を足す（2つ目以降はMP10消費）
    for b, bamboo in zip(bit, bamboos):
        if b == 1:
            if l1 > 0:
                c1 += 10
            l1 += bamboo
        elif b == 2:
            if l2 > 0:
                c2 += 10
            l2 += bamboo
        elif b == 3:
            if l3 > 0:
                c3 += 10
            l3 += bamboo
    # 1つも構成する竹がない竹がある場合はスキップ
    if l1 * l2 * l3 == 0:
        continue
    # 延長、短縮のコスト
    c1 += abs(b1 - l1)
    c2 += abs(b2 - l2)
    c3 += abs(b3 - l3)
    # 合計コストが今までより低ければ更新
    ans = min(ans, c1 + c2 + c3)
print(ans)

def dfs(cursor, a, b, c):
    if cursor == N:
        return (
            abs(A - a) + abs(B - b) + abs(C - c) - 30
            if min(a, b, c) > 0
            else float("inf")
        )
    ret0 = dfs(cursor + 1, a, b, c)
    ret1 = dfs(cursor + 1, a + l[cursor], b, c) + 10
    ret2 = dfs(cursor + 1, a, b + l[cursor], c) + 10
    ret3 = dfs(cursor + 1, a, b, c + l[cursor]) + 10
    return min(ret0, ret1, ret2, ret3)


N, A, B, C = [int(i) for i in input().split()]
l = [int(eval(input())) for _ in range(N)]
print((dfs(0, 0, 0, 0)))

-import itertools +def dfs(cursor, a, b, c): +    if cursor == N: +        return ( +            abs(A - a) + abs(B - b) + abs(C - c) - 30 +            if min(a, b, c) > 0 +            else float("inf") +        ) +    ret0 = dfs(cursor + 1, a, b, c) +    ret1 = dfs(cursor + 1, a + l[cursor], b, c) + 10 +    ret2 = dfs(cursor + 1, a, b + l[cursor], c) + 10 +    ret3 = dfs(cursor + 1, a, b, c + l[cursor]) + 10 +    return min(ret0, ret1, ret2, ret3) -n_bamboo, b1, b2, b3 = [int(i) for i in input().split()] -bamboos = [int(eval(input())) for _ in range(n_bamboo)] -ans = float("inf") -# すべての竹について、b1, b2, b3のどの竹に使うかを列挙 -# 0のときはどの竹にも使わない -for bit in itertools.product((0, 1, 2, 3), repeat=n_bamboo): -    l1, l2, l3 = 0, 0, 0 -    c1, c2, c3 = 0, 0, 0 -    # 選択した竹を足す（2つ目以降はMP10消費） -    for b, bamboo in zip(bit, bamboos): -        if b == 1: -            if l1 > 0: -                c1 += 10 -            l1 += bamboo -        elif b == 2: -            if l2 > 0: -                c2 += 10 -            l2 += bamboo -        elif b == 3: -            if l3 > 0: -                c3 += 10 -            l3 += bamboo -    # 1つも構成する竹がない竹がある場合はスキップ -    if l1 * l2 * l3 == 0: -        continue -    # 延長、短縮のコスト -    c1 += abs(b1 - l1) -    c2 += abs(b2 - l2) -    c3 += abs(b3 - l3) -    # 合計コストが今までより低ければ更新 -    ans = min(ans, c1 + c2 + c3) -print(ans) + +N, A, B, C = [int(i) for i in input().split()] +l = [int(eval(input())) for _ in range(N)] +print((dfs(0, 0, 0, 0)))