import itertools

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

x=[a,b,c]

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

ans=1000000

loop='012'

for i in range(2**n):

    use=[]

    for j in range(n):

        if((i>>j)&1):

            use.append(l[j])

    if(len(use)>=3):

        for j in (itertools.product(loop,repeat=len(use))):

            A=[[] for i in range(3)]

            for k in range(len(use)):

                A[int(j[k])].append(use[k])

                

            if(len(A[0])!=0 and len(A[1])!=0 and len(A[2])!=0):

                res=0

                for i in range(3):

                    res+=abs(sum(A[i])-x[i])+(len(A[i])-1)*10

                ans=min(res,ans)

print(ans)
def check(s,e,t):

    global ans

    if(not s or not e or not t):

        return

    ans=min(ans,(len(s)-1)*10+abs(A-sum(s))+(len(e)-1)*10+abs(B-sum(e))+(len(t)-1)*10+abs(C-sum(t)))



def dfs(s,e,t,i):

    if(i==N):

        check(s,e,t)

        return

    dfs(s,e,t,i+1)

    dfs(s+[l[i]],e,t,i+1)

    dfs(s,e+[l[i]],t,i+1)

    dfs(s,e,t+[l[i]],i+1)



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

l=[int(eval(input())) for i in range(N)]



ans=10**18

dfs([],[],[],0)

print(ans)
import itertools

n, a, b, c = list(map(int, input().split()))
x = [a, b, c]
l = [int(eval(input())) for i in range(n)]
ans = 1000000
loop = "012"
for i in range(2**n):
    use = []
    for j in range(n):
        if (i >> j) & 1:
            use.append(l[j])
    if len(use) >= 3:
        for j in itertools.product(loop, repeat=len(use)):
            A = [[] for i in range(3)]
            for k in range(len(use)):
                A[int(j[k])].append(use[k])
            if len(A[0]) != 0 and len(A[1]) != 0 and len(A[2]) != 0:
                res = 0
                for i in range(3):
                    res += abs(sum(A[i]) - x[i]) + (len(A[i]) - 1) * 10
                ans = min(res, ans)
print(ans)

def check(s, e, t):
    global ans
    if not s or not e or not t:
        return
    ans = min(
        ans,
        (len(s) - 1) * 10
        + abs(A - sum(s))
        + (len(e) - 1) * 10
        + abs(B - sum(e))
        + (len(t) - 1) * 10
        + abs(C - sum(t)),
    )


def dfs(s, e, t, i):
    if i == N:
        check(s, e, t)
        return
    dfs(s, e, t, i + 1)
    dfs(s + [l[i]], e, t, i + 1)
    dfs(s, e + [l[i]], t, i + 1)
    dfs(s, e, t + [l[i]], i + 1)


N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for i in range(N)]
ans = 10**18
dfs([], [], [], 0)
print(ans)

-import itertools +def check(s, e, t): +    global ans +    if not s or not e or not t: +        return +    ans = min( +        ans, +        (len(s) - 1) * 10 +        + abs(A - sum(s)) +        + (len(e) - 1) * 10 +        + abs(B - sum(e)) +        + (len(t) - 1) * 10 +        + abs(C - sum(t)), +    ) -n, a, b, c = list(map(int, input().split())) -x = [a, b, c] -l = [int(eval(input())) for i in range(n)] -ans = 1000000 -loop = "012" -for i in range(2**n): -    use = [] -    for j in range(n): -        if (i >> j) & 1: -            use.append(l[j]) -    if len(use) >= 3: -        for j in itertools.product(loop, repeat=len(use)): -            A = [[] for i in range(3)] -            for k in range(len(use)): -                A[int(j[k])].append(use[k]) -            if len(A[0]) != 0 and len(A[1]) != 0 and len(A[2]) != 0: -                res = 0 -                for i in range(3): -                    res += abs(sum(A[i]) - x[i]) + (len(A[i]) - 1) * 10 -                ans = min(res, ans) + +def dfs(s, e, t, i): +    if i == N: +        check(s, e, t) +        return +    dfs(s, e, t, i + 1) +    dfs(s + [l[i]], e, t, i + 1) +    dfs(s, e + [l[i]], t, i + 1) +    dfs(s, e, t + [l[i]], i + 1) + + +N, A, B, C = list(map(int, input().split())) +l = [int(eval(input())) for i in range(N)] +ans = 10**18 +dfs([], [], [], 0)