from itertools import product, permutations



N, A, B, C = list(map(int, input().split(' ')))

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



ans = 10 ** 9

for groups in product(list(range(4)), repeat=N):

    items = []

    group_a = []

    group_b = []

    group_c = []



    for group, length in zip(groups, L):

        if group == 0:

            items.append((length, 0))

        elif group == 1:

            group_a.append(length)

        elif group == 2:

            group_b.append(length)

        elif group == 3:

            group_c.append(length)



    if group_a:

        items.append((sum(group_a), (len(group_a) - 1) * 10))

    if group_b:

        items.append((sum(group_b), (len(group_b) - 1) * 10))

    if group_c:

        items.append((sum(group_c), (len(group_c) - 1) * 10))



    if len(items) < 3:

        continue



    for one, two, three in permutations((A, B, C), r=3):

        cost = 0

        _items = list(items)



        _items = sorted(_items, key=lambda x: (abs(x[0] - one), x[1]))

        cost += abs(_items[0][0] - one) + _items[0][1]

        _items.pop(0)



        _items = sorted(_items, key=lambda x: (abs(x[0] - two), x[1]))

        cost += abs(_items[0][0] - two) + _items[0][1]

        _items.pop(0)



        _items = sorted(_items, key=lambda x: (abs(x[0] - three), x[1]))

        cost += abs(_items[0][0] - three) + _items[0][1]



        ans = min(ans, cost)



print(ans)

from itertools import product



N, A, B, C = list(map(int, input().split(' ')))

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



ans = 10 ** 9

for groups in product(list(range(4)), repeat=N):

    length_a = 0

    length_b = 0

    length_c = 0

    cost_a = -10

    cost_b = -10

    cost_c = -10



    for group, length in zip(groups, L):

        if group == 1:

            length_a += length

            cost_a += 10

        elif group == 2:

            length_b += length

            cost_b += 10

        elif group == 3:

            length_c += length

            cost_c += 10



    if 0 in {length_a, length_b, length_c}:

        continue



    ans = min(ans, sum([

        abs(A - length_a),

        abs(B - length_b),

        abs(C - length_c),

        cost_a,

        cost_b,

        cost_c,

    ]))



print(ans)

from itertools import product, permutations

N, A, B, C = list(map(int, input().split(" ")))
L = [int(eval(input())) for _ in range(N)]
ans = 10**9
for groups in product(list(range(4)), repeat=N):
    items = []
    group_a = []
    group_b = []
    group_c = []
    for group, length in zip(groups, L):
        if group == 0:
            items.append((length, 0))
        elif group == 1:
            group_a.append(length)
        elif group == 2:
            group_b.append(length)
        elif group == 3:
            group_c.append(length)
    if group_a:
        items.append((sum(group_a), (len(group_a) - 1) * 10))
    if group_b:
        items.append((sum(group_b), (len(group_b) - 1) * 10))
    if group_c:
        items.append((sum(group_c), (len(group_c) - 1) * 10))
    if len(items) < 3:
        continue
    for one, two, three in permutations((A, B, C), r=3):
        cost = 0
        _items = list(items)
        _items = sorted(_items, key=lambda x: (abs(x[0] - one), x[1]))
        cost += abs(_items[0][0] - one) + _items[0][1]
        _items.pop(0)
        _items = sorted(_items, key=lambda x: (abs(x[0] - two), x[1]))
        cost += abs(_items[0][0] - two) + _items[0][1]
        _items.pop(0)
        _items = sorted(_items, key=lambda x: (abs(x[0] - three), x[1]))
        cost += abs(_items[0][0] - three) + _items[0][1]
        ans = min(ans, cost)
print(ans)

from itertools import product

N, A, B, C = list(map(int, input().split(" ")))
L = [int(eval(input())) for _ in range(N)]
ans = 10**9
for groups in product(list(range(4)), repeat=N):
    length_a = 0
    length_b = 0
    length_c = 0
    cost_a = -10
    cost_b = -10
    cost_c = -10
    for group, length in zip(groups, L):
        if group == 1:
            length_a += length
            cost_a += 10
        elif group == 2:
            length_b += length
            cost_b += 10
        elif group == 3:
            length_c += length
            cost_c += 10
    if 0 in {length_a, length_b, length_c}:
        continue
    ans = min(
        ans,
        sum(
            [
                abs(A - length_a),
                abs(B - length_b),
                abs(C - length_c),
                cost_a,
                cost_b,
                cost_c,
            ]
        ),
    )
print(ans)

-from itertools import product, permutations +from itertools import product -    items = [] -    group_a = [] -    group_b = [] -    group_c = [] +    length_a = 0 +    length_b = 0 +    length_c = 0 +    cost_a = -10 +    cost_b = -10 +    cost_c = -10 -        if group == 0: -            items.append((length, 0)) -        elif group == 1: -            group_a.append(length) +        if group == 1: +            length_a += length +            cost_a += 10 -            group_b.append(length) +            length_b += length +            cost_b += 10 -            group_c.append(length) -    if group_a: -        items.append((sum(group_a), (len(group_a) - 1) * 10)) -    if group_b: -        items.append((sum(group_b), (len(group_b) - 1) * 10)) -    if group_c: -        items.append((sum(group_c), (len(group_c) - 1) * 10)) -    if len(items) < 3: +            length_c += length +            cost_c += 10 +    if 0 in {length_a, length_b, length_c}: -    for one, two, three in permutations((A, B, C), r=3): -        cost = 0 -        _items = list(items) -        _items = sorted(_items, key=lambda x: (abs(x[0] - one), x[1])) -        cost += abs(_items[0][0] - one) + _items[0][1] -        _items.pop(0) -        _items = sorted(_items, key=lambda x: (abs(x[0] - two), x[1])) -        cost += abs(_items[0][0] - two) + _items[0][1] -        _items.pop(0) -        _items = sorted(_items, key=lambda x: (abs(x[0] - three), x[1])) -        cost += abs(_items[0][0] - three) + _items[0][1] -        ans = min(ans, cost) +    ans = min( +        ans, +        sum( +            [ +                abs(A - length_a), +                abs(B - length_b), +                abs(C - length_c), +                cost_a, +                cost_b, +                cost_c, +            ] +        ), +    )