import bisect

INF=10**18

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

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

ans=INF

for i in range(4**n):

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

  for j in range(n):

    if (i>>2*j)&1 and not (i>>2*j+1)&1:x[0].append(l[j])

    if not (i>>2*j)&1 and (i>>2*j+1)&1:x[1].append(l[j])

    if (i>>2*j)&1 and (i>>2*j+1)&1:x[2].append(l[j])

  cnt=0

  for j in range(3):

    if len(x[j])==0:cnt=INF

    cnt+=(len(x[j])-1)*10+abs(sum(x[j])-a[j])

  ans=min(ans,cnt)

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

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

ans=10**18

for i in range(4**n):

  la,lb,lc,ca,cb,cc=0,0,0,0,0,0

  for j in range(n):

    if (i>>2*j)&1 and not (i>>2*j+1)&1:

      ca+=1

      la+=l[j]

    if not (i>>2*j)&1 and (i>>2*j+1)&1:

      cb+=1

      lb+=l[j]

    if (i>>2*j)&1 and (i>>2*j+1)&1:

      cc+=1

      lc+=l[j]

  if ca*cb*cc:ans=min((ca+cb+cc-3)*10+abs(la-a)+abs(lb-b)+abs(lc-c),ans)

print(ans)
import bisect

INF = 10**18
n, *a = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
ans = INF
for i in range(4**n):
    x = [[] for _ in range(3)]
    for j in range(n):
        if (i >> 2 * j) & 1 and not (i >> 2 * j + 1) & 1:
            x[0].append(l[j])
        if not (i >> 2 * j) & 1 and (i >> 2 * j + 1) & 1:
            x[1].append(l[j])
        if (i >> 2 * j) & 1 and (i >> 2 * j + 1) & 1:
            x[2].append(l[j])
    cnt = 0
    for j in range(3):
        if len(x[j]) == 0:
            cnt = INF
        cnt += (len(x[j]) - 1) * 10 + abs(sum(x[j]) - a[j])
    ans = min(ans, cnt)
print(ans)

n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
ans = 10**18
for i in range(4**n):
    la, lb, lc, ca, cb, cc = 0, 0, 0, 0, 0, 0
    for j in range(n):
        if (i >> 2 * j) & 1 and not (i >> 2 * j + 1) & 1:
            ca += 1
            la += l[j]
        if not (i >> 2 * j) & 1 and (i >> 2 * j + 1) & 1:
            cb += 1
            lb += l[j]
        if (i >> 2 * j) & 1 and (i >> 2 * j + 1) & 1:
            cc += 1
            lc += l[j]
    if ca * cb * cc:
        ans = min(
            (ca + cb + cc - 3) * 10 + abs(la - a) + abs(lb - b) + abs(lc - c), ans
        )
print(ans)

-import bisect - -INF = 10**18 -n, *a = list(map(int, input().split())) +n, a, b, c = list(map(int, input().split())) -ans = INF +ans = 10**18 -    x = [[] for _ in range(3)] +    la, lb, lc, ca, cb, cc = 0, 0, 0, 0, 0, 0 -            x[0].append(l[j]) +            ca += 1 +            la += l[j] -            x[1].append(l[j]) +            cb += 1 +            lb += l[j] -            x[2].append(l[j]) -    cnt = 0 -    for j in range(3): -        if len(x[j]) == 0: -            cnt = INF -        cnt += (len(x[j]) - 1) * 10 + abs(sum(x[j]) - a[j]) -    ans = min(ans, cnt) +            cc += 1 +            lc += l[j] +    if ca * cb * cc: +        ans = min( +            (ca + cb + cc - 3) * 10 + abs(la - a) + abs(lb - b) + abs(lc - c), ans +        )