def main():

    from itertools import product



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

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



    ans = 3000

    for prod in product([0, 1, 2, 3], repeat=N):

        t = [[] for _ in range(3)]

        for i, x in enumerate(prod):

            if x == 3: continue

            t[x].append(i)

        if (not t[0]) or (not t[1]) or (not t[2]): continue



        cost = sum(len(t[i]) - 1 for i in range(3)) * 10

        a = sum(L[i] for i in t[0])

        b = sum(L[i] for i in t[1])

        c = sum(L[i] for i in t[2])

        cost += abs(A - a) + abs(B - b) + abs(C - c)

        if ans > cost:

            ans = cost



    print(ans)





if __name__ == '__main__':

    main()

from itertools import product



INF = 10 ** 9



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

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





def estimate(lst):

    if any(not p for p in lst):

        return INF



    ret = 0

    for p, g in zip(lst, A):

        ret += abs(g - sum(p)) + (len(p) - 1) * 10

    return ret





ans = INF

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

    pieces = [[] for _ in range(3)]

    for bamboo_ind, target_kadomatsu in enumerate(prd):

        if target_kadomatsu == 3: continue

        pieces[target_kadomatsu].append(L[bamboo_ind])

    if ans > (res := estimate(pieces)):

        ans = res

print(ans)

def main():
    from itertools import product

    N, A, B, C = list(map(int, input().split()))
    L = [int(eval(input())) for _ in range(N)]
    ans = 3000
    for prod in product([0, 1, 2, 3], repeat=N):
        t = [[] for _ in range(3)]
        for i, x in enumerate(prod):
            if x == 3:
                continue
            t[x].append(i)
        if (not t[0]) or (not t[1]) or (not t[2]):
            continue
        cost = sum(len(t[i]) - 1 for i in range(3)) * 10
        a = sum(L[i] for i in t[0])
        b = sum(L[i] for i in t[1])
        c = sum(L[i] for i in t[2])
        cost += abs(A - a) + abs(B - b) + abs(C - c)
        if ans > cost:
            ans = cost
    print(ans)


if __name__ == "__main__":
    main()

from itertools import product

INF = 10**9
N, *A = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]


def estimate(lst):
    if any(not p for p in lst):
        return INF
    ret = 0
    for p, g in zip(lst, A):
        ret += abs(g - sum(p)) + (len(p) - 1) * 10
    return ret


ans = INF
for prd in product(list(range(4)), repeat=N):
    pieces = [[] for _ in range(3)]
    for bamboo_ind, target_kadomatsu in enumerate(prd):
        if target_kadomatsu == 3:
            continue
        pieces[target_kadomatsu].append(L[bamboo_ind])
    if ans > (res := estimate(pieces)):
        ans = res
print(ans)

-def main(): -    from itertools import product +from itertools import product -    N, A, B, C = list(map(int, input().split())) -    L = [int(eval(input())) for _ in range(N)] -    ans = 3000 -    for prod in product([0, 1, 2, 3], repeat=N): -        t = [[] for _ in range(3)] -        for i, x in enumerate(prod): -            if x == 3: -                continue -            t[x].append(i) -        if (not t[0]) or (not t[1]) or (not t[2]): -            continue -        cost = sum(len(t[i]) - 1 for i in range(3)) * 10 -        a = sum(L[i] for i in t[0]) -        b = sum(L[i] for i in t[1]) -        c = sum(L[i] for i in t[2]) -        cost += abs(A - a) + abs(B - b) + abs(C - c) -        if ans > cost: -            ans = cost -    print(ans) +INF = 10**9 +N, *A = list(map(int, input().split())) +L = [int(eval(input())) for _ in range(N)] -if __name__ == "__main__": -    main() +def estimate(lst): +    if any(not p for p in lst): +        return INF +    ret = 0 +    for p, g in zip(lst, A): +        ret += abs(g - sum(p)) + (len(p) - 1) * 10 +    return ret + + +ans = INF +for prd in product(list(range(4)), repeat=N): +    pieces = [[] for _ in range(3)] +    for bamboo_ind, target_kadomatsu in enumerate(prd): +        if target_kadomatsu == 3: +            continue +        pieces[target_kadomatsu].append(L[bamboo_ind]) +    if ans > (res := estimate(pieces)): +        ans = res +print(ans)