import itertools



n, a, b, c = list(map(int, input().split()))

_l = [int(eval(input())) for i in range(n)]



cl = ('A', 'B', 'C', 'N')



result = 1e10

for pattern in itertools.product(*[cl]*n):

    wands = {'A': 0, 'B': 0, 'C': 0}

    point = 0

    for i, char in enumerate(pattern):

        if char != 'N':

            if wands[char] != 0:

                point += 10

            wands[char] += _l[i]

    if min(wands.values()) > 0:

        point += abs(wands['A'] - a) + abs(wands['B'] - b) + abs(wands['C'] - c)

        if point < result:

            result = point



print(result)

n, a, b, c = list(map(int, input().split()))

_l = [int(eval(input())) for i in range(n)]



inf = 10**9





# DP

def f(i, _a, _b, _c):

    # A,B,Cにしようとしている枝の長さが現在_a,_b,_cのとき,i番目以降の材料を使って達成される点数の最小値

    if i == n:

        return abs(a - _a) + abs(b - _b) + abs(c - _c) if min(_a, _b, _c) > 0 else inf



    # i番目を使わないとき

    val1 = f(i + 1, _a, _b, _c)

    # i番目をAに使うとき

    val2 = f(i + 1, _a + _l[i], _b, _c) + (0 if _a == 0 else 10)

    val3 = f(i + 1, _a, _b + _l[i], _c) + (0 if _b == 0 else 10)

    val4 = f(i + 1, _a, _b, _c + _l[i]) + (0 if _c == 0 else 10)

    return min(val1, val2, val3, val4)





print((f(0, 0, 0, 0)))

import itertools

n, a, b, c = list(map(int, input().split()))
_l = [int(eval(input())) for i in range(n)]
cl = ("A", "B", "C", "N")
result = 1e10
for pattern in itertools.product(*[cl] * n):
    wands = {"A": 0, "B": 0, "C": 0}
    point = 0
    for i, char in enumerate(pattern):
        if char != "N":
            if wands[char] != 0:
                point += 10
            wands[char] += _l[i]
    if min(wands.values()) > 0:
        point += abs(wands["A"] - a) + abs(wands["B"] - b) + abs(wands["C"] - c)
        if point < result:
            result = point
print(result)

n, a, b, c = list(map(int, input().split()))
_l = [int(eval(input())) for i in range(n)]
inf = 10**9
# DP
def f(i, _a, _b, _c):
    # A,B,Cにしようとしている枝の長さが現在_a,_b,_cのとき,i番目以降の材料を使って達成される点数の最小値
    if i == n:
        return abs(a - _a) + abs(b - _b) + abs(c - _c) if min(_a, _b, _c) > 0 else inf
    # i番目を使わないとき
    val1 = f(i + 1, _a, _b, _c)
    # i番目をAに使うとき
    val2 = f(i + 1, _a + _l[i], _b, _c) + (0 if _a == 0 else 10)
    val3 = f(i + 1, _a, _b + _l[i], _c) + (0 if _b == 0 else 10)
    val4 = f(i + 1, _a, _b, _c + _l[i]) + (0 if _c == 0 else 10)
    return min(val1, val2, val3, val4)


print((f(0, 0, 0, 0)))

-import itertools - -cl = ("A", "B", "C", "N") -result = 1e10 -for pattern in itertools.product(*[cl] * n): -    wands = {"A": 0, "B": 0, "C": 0} -    point = 0 -    for i, char in enumerate(pattern): -        if char != "N": -            if wands[char] != 0: -                point += 10 -            wands[char] += _l[i] -    if min(wands.values()) > 0: -        point += abs(wands["A"] - a) + abs(wands["B"] - b) + abs(wands["C"] - c) -        if point < result: -            result = point -print(result) +inf = 10**9 +# DP +def f(i, _a, _b, _c): +    # A,B,Cにしようとしている枝の長さが現在_a,_b,_cのとき,i番目以降の材料を使って達成される点数の最小値 +    if i == n: +        return abs(a - _a) + abs(b - _b) + abs(c - _c) if min(_a, _b, _c) > 0 else inf +    # i番目を使わないとき +    val1 = f(i + 1, _a, _b, _c) +    # i番目をAに使うとき +    val2 = f(i + 1, _a + _l[i], _b, _c) + (0 if _a == 0 else 10) +    val3 = f(i + 1, _a, _b + _l[i], _c) + (0 if _b == 0 else 10) +    val4 = f(i + 1, _a, _b, _c + _l[i]) + (0 if _c == 0 else 10) +    return min(val1, val2, val3, val4) + + +print((f(0, 0, 0, 0)))