from itertools import permutations



def main():

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

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



    # full search

    ans = 10**9

    for perm in permutations(l):

        cost = -30

        for i in range(1, n-1):

            cost1 = cost + 10 * len(perm[:i]) + abs(a - sum(perm[:i]))

            for j in range(i+1, n):

                cost2 = cost1 + 10 * len(perm[i:j]) + abs(b - sum(perm[i:j]))

                for k in range(j+1, n+1):

                    cost3 = cost2 + 10 * len(perm[j:k]) + abs(c - sum(perm[j:k]))

                    if cost3 < ans:

                        ans = cost3



    print(ans)



main()
from itertools import product

from sys import stdin

input = stdin.buffer.readline



def main():

    n, *abc = list(map(int, input().split()))

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



    ans = 10**9

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

        cost = 10 * (n-3)

        lengths = [0, 0, 0]

        for i, x in enumerate(prod):

            if x < 3:

                lengths[x] += l[i]

            else:

                cost -= 10



        for i in lengths:

            if i == 0:

                break



        else:

            for i, x in enumerate(abc):

                cost += abs(x - lengths[i])

            if cost < ans:

                ans = cost



    print(ans)



main()
from itertools import permutations


def main():
    n, a, b, c = list(map(int, input().split()))
    l = [int(eval(input())) for _ in range(n)]
    # full search
    ans = 10**9
    for perm in permutations(l):
        cost = -30
        for i in range(1, n - 1):
            cost1 = cost + 10 * len(perm[:i]) + abs(a - sum(perm[:i]))
            for j in range(i + 1, n):
                cost2 = cost1 + 10 * len(perm[i:j]) + abs(b - sum(perm[i:j]))
                for k in range(j + 1, n + 1):
                    cost3 = cost2 + 10 * len(perm[j:k]) + abs(c - sum(perm[j:k]))
                    if cost3 < ans:
                        ans = cost3
    print(ans)


main()

from itertools import product
from sys import stdin

input = stdin.buffer.readline


def main():
    n, *abc = list(map(int, input().split()))
    l = [int(eval(input())) for _ in range(n)]
    ans = 10**9
    for prod in product([0, 1, 2, 3], repeat=n):
        cost = 10 * (n - 3)
        lengths = [0, 0, 0]
        for i, x in enumerate(prod):
            if x < 3:
                lengths[x] += l[i]
            else:
                cost -= 10
        for i in lengths:
            if i == 0:
                break
        else:
            for i, x in enumerate(abc):
                cost += abs(x - lengths[i])
            if cost < ans:
                ans = cost
    print(ans)


main()

-from itertools import permutations +from itertools import product +from sys import stdin + +input = stdin.buffer.readline -    n, a, b, c = list(map(int, input().split())) +    n, *abc = list(map(int, input().split())) -    # full search -    for perm in permutations(l): -        cost = -30 -        for i in range(1, n - 1): -            cost1 = cost + 10 * len(perm[:i]) + abs(a - sum(perm[:i])) -            for j in range(i + 1, n): -                cost2 = cost1 + 10 * len(perm[i:j]) + abs(b - sum(perm[i:j])) -                for k in range(j + 1, n + 1): -                    cost3 = cost2 + 10 * len(perm[j:k]) + abs(c - sum(perm[j:k])) -                    if cost3 < ans: -                        ans = cost3 +    for prod in product([0, 1, 2, 3], repeat=n): +        cost = 10 * (n - 3) +        lengths = [0, 0, 0] +        for i, x in enumerate(prod): +            if x < 3: +                lengths[x] += l[i] +            else: +                cost -= 10 +        for i in lengths: +            if i == 0: +                break +        else: +            for i, x in enumerate(abc): +                cost += abs(x - lengths[i]) +            if cost < ans: +                ans = cost