from itertools import product

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

abc=[a,b,c]

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



ans=10**18

for a in product(list(range(4)), repeat=n):

    MP=0

    take=[[] for _ in range(4)]



    for i in range(n):

        take[a[i]].append(l[i])

    

    if take[0] and take[1] and take[2]:

        for i,t in enumerate(take[:-1]):

            MP+=max(0, 10*(len(t)-1))

            MP+=abs(abc[i] - sum(t))

    else:

        continue



    ans=min(ans, MP) 



print(ans)

from itertools import product

import sys

input = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 7)



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

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



ans = 10 ** 18

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

    La = 0

    Lb = 0

    Lc = 0

    use_a = 0

    use_b = 0

    use_c = 0

    for i, f in enumerate(alloc):

        if f == 0:

            La += L[i]

            use_a += 1

        elif f == 1:

            Lb += L[i]

            use_b += 1

        elif f == 2:

            Lc += L[i]

            use_c += 1

        else:

            pass



    if not all([use_a, use_b, use_c]):

        continue



    score = 0

    score += 10 * (use_a - 1)

    score += 10 * (use_b - 1)

    score += 10 * (use_c - 1)

    score += abs(A - La)

    score += abs(B - Lb)

    score += abs(C - Lc)

    ans = min(ans, score)



print(ans)
from itertools import product

n, a, b, c = list(map(int, input().split()))
abc = [a, b, c]
l = tuple(int(eval(input())) for _ in range(n))
ans = 10**18
for a in product(list(range(4)), repeat=n):
    MP = 0
    take = [[] for _ in range(4)]
    for i in range(n):
        take[a[i]].append(l[i])
    if take[0] and take[1] and take[2]:
        for i, t in enumerate(take[:-1]):
            MP += max(0, 10 * (len(t) - 1))
            MP += abs(abc[i] - sum(t))
    else:
        continue
    ans = min(ans, MP)
print(ans)

from itertools import product
import sys

input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
ans = 10**18
for alloc in product(list(range(4)), repeat=N):
    La = 0
    Lb = 0
    Lc = 0
    use_a = 0
    use_b = 0
    use_c = 0
    for i, f in enumerate(alloc):
        if f == 0:
            La += L[i]
            use_a += 1
        elif f == 1:
            Lb += L[i]
            use_b += 1
        elif f == 2:
            Lc += L[i]
            use_c += 1
        else:
            pass
    if not all([use_a, use_b, use_c]):
        continue
    score = 0
    score += 10 * (use_a - 1)
    score += 10 * (use_b - 1)
    score += 10 * (use_c - 1)
    score += abs(A - La)
    score += abs(B - Lb)
    score += abs(C - Lc)
    ans = min(ans, score)
print(ans)

+import sys -n, a, b, c = list(map(int, input().split())) -abc = [a, b, c] -l = tuple(int(eval(input())) for _ in range(n)) +input = sys.stdin.buffer.readline +sys.setrecursionlimit(10**7) +N, A, B, C = list(map(int, input().split())) +L = [int(eval(input())) for _ in range(N)] -for a in product(list(range(4)), repeat=n): -    MP = 0 -    take = [[] for _ in range(4)] -    for i in range(n): -        take[a[i]].append(l[i]) -    if take[0] and take[1] and take[2]: -        for i, t in enumerate(take[:-1]): -            MP += max(0, 10 * (len(t) - 1)) -            MP += abs(abc[i] - sum(t)) -    else: +for alloc in product(list(range(4)), repeat=N): +    La = 0 +    Lb = 0 +    Lc = 0 +    use_a = 0 +    use_b = 0 +    use_c = 0 +    for i, f in enumerate(alloc): +        if f == 0: +            La += L[i] +            use_a += 1 +        elif f == 1: +            Lb += L[i] +            use_b += 1 +        elif f == 2: +            Lc += L[i] +            use_c += 1 +        else: +            pass +    if not all([use_a, use_b, use_c]): -    ans = min(ans, MP) +    score = 0 +    score += 10 * (use_a - 1) +    score += 10 * (use_b - 1) +    score += 10 * (use_c - 1) +    score += abs(A - La) +    score += abs(B - Lb) +    score += abs(C - Lc) +    ans = min(ans, score)