from itertools import product

import bisect



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

tl = [C,B,A]



ll = []

for _ in range(N):

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







ans = 10**8

ite = product(list(range(4)),repeat=N)

for pattern in ite:

    bag = [[],[],[]]

    singles = []

    mp = 0

    for i, p in enumerate(pattern):

        if p == 3: singles.append(ll[i])

        else: bag[p].append(ll[i])

    

    zero_cnt = 0

    for b in bag:

        if not b: zero_cnt+=1

        else: mp += (len(b)-1)*10

    if not singles: zero_cnt+=1

    if zero_cnt >= 2: continue



    bamboos = []

    for b in bag:

        if b: bamboos.append(sum(b))

    for s in singles:

        bamboos.append(s)



    bamboos.sort()

    # print(bamboos)

    

    for t in tl:

        curr_min = 10000

        curr_min_i = 0

        for i, ba in enumerate(bamboos):

            if abs(ba - t) < curr_min:

                curr_min = abs(ba-t)

                curr_min_i = i

        mp += curr_min

        bamboos.pop(curr_min_i)



    ans = min(ans,mp)



print(ans)


from itertools import product



def main():

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

    targetl = [a,b,c]

    targetl.sort()

    ll = []

    for _ in range(n):

        l = int(eval(input()))

        ll.append(l)



    ans = 10**9

    ite = product(list(range(4)),repeat=n)

    ite = list(ite)

    for it in ite:

        bamboosl = [ [],[],[] ]

        cost = -30

        for i,v in enumerate(it):

            if v != 3:

                bamboosl[v].append(ll[i])

                cost += 10



        continue_f = False    

        for bamboos in bamboosl:

            if not bamboos: continue_f = True

        if continue_f: continue



        longs = []

        for bamboos in bamboosl:

            curr_l = sum(bamboos)

            longs.append(curr_l)

        longs.sort()



        for v1,v2 in zip(targetl,longs):

            cost += abs(v1-v2)

            

        ans = min(ans,cost)



    print(ans)





if __name__ == "__main__":

    main()
from itertools import product
import bisect

N, A, B, C = list(map(int, input().split()))
tl = [C, B, A]
ll = []
for _ in range(N):
    ll.append(int(eval(input())))
ans = 10**8
ite = product(list(range(4)), repeat=N)
for pattern in ite:
    bag = [[], [], []]
    singles = []
    mp = 0
    for i, p in enumerate(pattern):
        if p == 3:
            singles.append(ll[i])
        else:
            bag[p].append(ll[i])
    zero_cnt = 0
    for b in bag:
        if not b:
            zero_cnt += 1
        else:
            mp += (len(b) - 1) * 10
    if not singles:
        zero_cnt += 1
    if zero_cnt >= 2:
        continue
    bamboos = []
    for b in bag:
        if b:
            bamboos.append(sum(b))
    for s in singles:
        bamboos.append(s)
    bamboos.sort()
    # print(bamboos)
    for t in tl:
        curr_min = 10000
        curr_min_i = 0
        for i, ba in enumerate(bamboos):
            if abs(ba - t) < curr_min:
                curr_min = abs(ba - t)
                curr_min_i = i
        mp += curr_min
        bamboos.pop(curr_min_i)
    ans = min(ans, mp)
print(ans)

from itertools import product


def main():
    n, a, b, c = list(map(int, input().split()))
    targetl = [a, b, c]
    targetl.sort()
    ll = []
    for _ in range(n):
        l = int(eval(input()))
        ll.append(l)
    ans = 10**9
    ite = product(list(range(4)), repeat=n)
    ite = list(ite)
    for it in ite:
        bamboosl = [[], [], []]
        cost = -30
        for i, v in enumerate(it):
            if v != 3:
                bamboosl[v].append(ll[i])
                cost += 10
        continue_f = False
        for bamboos in bamboosl:
            if not bamboos:
                continue_f = True
        if continue_f:
            continue
        longs = []
        for bamboos in bamboosl:
            curr_l = sum(bamboos)
            longs.append(curr_l)
        longs.sort()
        for v1, v2 in zip(targetl, longs):
            cost += abs(v1 - v2)
        ans = min(ans, cost)
    print(ans)


if __name__ == "__main__":
    main()

-import bisect -N, A, B, C = list(map(int, input().split())) -tl = [C, B, A] -ll = [] -for _ in range(N): -    ll.append(int(eval(input()))) -ans = 10**8 -ite = product(list(range(4)), repeat=N) -for pattern in ite: -    bag = [[], [], []] -    singles = [] -    mp = 0 -    for i, p in enumerate(pattern): -        if p == 3: -            singles.append(ll[i]) -        else: -            bag[p].append(ll[i]) -    zero_cnt = 0 -    for b in bag: -        if not b: -            zero_cnt += 1 -        else: -            mp += (len(b) - 1) * 10 -    if not singles: -        zero_cnt += 1 -    if zero_cnt >= 2: -        continue -    bamboos = [] -    for b in bag: -        if b: -            bamboos.append(sum(b)) -    for s in singles: -        bamboos.append(s) -    bamboos.sort() -    # print(bamboos) -    for t in tl: -        curr_min = 10000 -        curr_min_i = 0 -        for i, ba in enumerate(bamboos): -            if abs(ba - t) < curr_min: -                curr_min = abs(ba - t) -                curr_min_i = i -        mp += curr_min -        bamboos.pop(curr_min_i) -    ans = min(ans, mp) -print(ans) + +def main(): +    n, a, b, c = list(map(int, input().split())) +    targetl = [a, b, c] +    targetl.sort() +    ll = [] +    for _ in range(n): +        l = int(eval(input())) +        ll.append(l) +    ans = 10**9 +    ite = product(list(range(4)), repeat=n) +    ite = list(ite) +    for it in ite: +        bamboosl = [[], [], []] +        cost = -30 +        for i, v in enumerate(it): +            if v != 3: +                bamboosl[v].append(ll[i]) +                cost += 10 +        continue_f = False +        for bamboos in bamboosl: +            if not bamboos: +                continue_f = True +        if continue_f: +            continue +        longs = [] +        for bamboos in bamboosl: +            curr_l = sum(bamboos) +            longs.append(curr_l) +        longs.sort() +        for v1, v2 in zip(targetl, longs): +            cost += abs(v1 - v2) +        ans = min(ans, cost) +    print(ans) + + +if __name__ == "__main__": +    main()