#!/usr/bin/env python

# coding: utf-8



import itertools



def main():

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

    ll = []

    for _ in range(N):

        ll.append(int(eval(input())))



    cand = []

    ids = set(range(N))

    for a in range(1, N-1):

        for b in range(1, N-a):

            for c in range(1, N-a-b+1):

                cand.append((a, b, c))

    best_cost = -1

    for a, b, c in cand:

        la = itertools.combinations(ids, a)

        for a_ in la:

            lb = itertools.combinations(ids-set(a_), b)

            for b_ in lb:

                lc = itertools.combinations(ids-set(a_)-set(b_), c)

                for c_ in lc:

                    cost = (len(a_)-1)*10 + abs(sum(ll[e] for e in a_)-A)

                    cost += (len(b_)-1)*10 + abs(sum(ll[e] for e in b_)-B)

                    cost += (len(c_)-1)*10 + abs(sum(ll[e] for e in c_)-C)

                    if best_cost == -1 or cost < best_cost:

                        best_cost = cost

    print(best_cost)





if __name__ == '__main__':

    main()

#!/usr/bin/env python

# coding: utf-8



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

ll = []

for _ in range(N):

    ll.append(int(eval(input())))



def dfs(n, a, b, c):

    if n == N:

        if a == 0 or b == 0 or c == 0: return float('inf')

        return abs(A-a) + abs(B-b) + abs(C-c)

    ca = dfs(n+1, a+ll[n], b, c)

    if a > 0: ca += 10

    cb = dfs(n+1, a, b+ll[n], c)

    if b > 0: cb += 10

    cc = dfs(n+1, a, b, c+ll[n])

    if c > 0: cc += 10

    cn = dfs(n+1, a, b, c)

    return min(ca, cb, cc, cn)





def main():

    print((dfs(0, 0, 0, 0)))





if __name__ == '__main__':

    main()

#!/usr/bin/env python
# coding: utf-8
import itertools


def main():
    N, A, B, C = list(map(int, input().split()))
    ll = []
    for _ in range(N):
        ll.append(int(eval(input())))
    cand = []
    ids = set(range(N))
    for a in range(1, N - 1):
        for b in range(1, N - a):
            for c in range(1, N - a - b + 1):
                cand.append((a, b, c))
    best_cost = -1
    for a, b, c in cand:
        la = itertools.combinations(ids, a)
        for a_ in la:
            lb = itertools.combinations(ids - set(a_), b)
            for b_ in lb:
                lc = itertools.combinations(ids - set(a_) - set(b_), c)
                for c_ in lc:
                    cost = (len(a_) - 1) * 10 + abs(sum(ll[e] for e in a_) - A)
                    cost += (len(b_) - 1) * 10 + abs(sum(ll[e] for e in b_) - B)
                    cost += (len(c_) - 1) * 10 + abs(sum(ll[e] for e in c_) - C)
                    if best_cost == -1 or cost < best_cost:
                        best_cost = cost
    print(best_cost)


if __name__ == "__main__":
    main()

#!/usr/bin/env python
# coding: utf-8
N, A, B, C = list(map(int, input().split()))
ll = []
for _ in range(N):
    ll.append(int(eval(input())))


def dfs(n, a, b, c):
    if n == N:
        if a == 0 or b == 0 or c == 0:
            return float("inf")
        return abs(A - a) + abs(B - b) + abs(C - c)
    ca = dfs(n + 1, a + ll[n], b, c)
    if a > 0:
        ca += 10
    cb = dfs(n + 1, a, b + ll[n], c)
    if b > 0:
        cb += 10
    cc = dfs(n + 1, a, b, c + ll[n])
    if c > 0:
        cc += 10
    cn = dfs(n + 1, a, b, c)
    return min(ca, cb, cc, cn)


def main():
    print((dfs(0, 0, 0, 0)))


if __name__ == "__main__":
    main()

-import itertools +N, A, B, C = list(map(int, input().split())) +ll = [] +for _ in range(N): +    ll.append(int(eval(input()))) + + +def dfs(n, a, b, c): +    if n == N: +        if a == 0 or b == 0 or c == 0: +            return float("inf") +        return abs(A - a) + abs(B - b) + abs(C - c) +    ca = dfs(n + 1, a + ll[n], b, c) +    if a > 0: +        ca += 10 +    cb = dfs(n + 1, a, b + ll[n], c) +    if b > 0: +        cb += 10 +    cc = dfs(n + 1, a, b, c + ll[n]) +    if c > 0: +        cc += 10 +    cn = dfs(n + 1, a, b, c) +    return min(ca, cb, cc, cn) -    N, A, B, C = list(map(int, input().split())) -    ll = [] -    for _ in range(N): -        ll.append(int(eval(input()))) -    cand = [] -    ids = set(range(N)) -    for a in range(1, N - 1): -        for b in range(1, N - a): -            for c in range(1, N - a - b + 1): -                cand.append((a, b, c)) -    best_cost = -1 -    for a, b, c in cand: -        la = itertools.combinations(ids, a) -        for a_ in la: -            lb = itertools.combinations(ids - set(a_), b) -            for b_ in lb: -                lc = itertools.combinations(ids - set(a_) - set(b_), c) -                for c_ in lc: -                    cost = (len(a_) - 1) * 10 + abs(sum(ll[e] for e in a_) - A) -                    cost += (len(b_) - 1) * 10 + abs(sum(ll[e] for e in b_) - B) -                    cost += (len(c_) - 1) * 10 + abs(sum(ll[e] for e in c_) - C) -                    if best_cost == -1 or cost < best_cost: -                        best_cost = cost -    print(best_cost) +    print((dfs(0, 0, 0, 0)))