from itertools import product

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

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

s=10**9

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

  if {0,1,2}<=set(P):

    m=[0,0,0]

    for x,y in zip(P,A):

      if x!=3:

        m[x]+=y

    t=sum(abs(m-y) for m,y in zip(m,B))

    l=sum(1 for j in P if j!=3)-3

    s=min(s,t+l*10)

print(s)
from itertools import *

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

L = [int(eval(input())) for n in range(N)]

ans = []



for i in product(list(range(4)),repeat=N):

  a = 0

  b = 0

  c = 0

  d = 0

  for j in range(N):

    if i[j]:

      d+=1

      if i[j]==1:

        a+=L[j]

      elif i[j]==2:

        b+=L[j]

      else:

        c+=L[j]

  if a*b*c:

    ans+=[abs(A-a)+abs(B-b)+abs(C-c)+10*(d-3)]



print((min(ans)))
from itertools import product

n, *B = list(map(int, input().split()))
A = [int(eval(input())) for i in range(n)]
s = 10**9
for P in product([0, 1, 2, 3], repeat=n):
    if {0, 1, 2} <= set(P):
        m = [0, 0, 0]
        for x, y in zip(P, A):
            if x != 3:
                m[x] += y
        t = sum(abs(m - y) for m, y in zip(m, B))
        l = sum(1 for j in P if j != 3) - 3
        s = min(s, t + l * 10)
print(s)

from itertools import *

N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for n in range(N)]
ans = []
for i in product(list(range(4)), repeat=N):
    a = 0
    b = 0
    c = 0
    d = 0
    for j in range(N):
        if i[j]:
            d += 1
            if i[j] == 1:
                a += L[j]
            elif i[j] == 2:
                b += L[j]
            else:
                c += L[j]
    if a * b * c:
        ans += [abs(A - a) + abs(B - b) + abs(C - c) + 10 * (d - 3)]
print((min(ans)))

-from itertools import product +from itertools import * -n, *B = list(map(int, input().split())) -A = [int(eval(input())) for i in range(n)] -s = 10**9 -for P in product([0, 1, 2, 3], repeat=n): -    if {0, 1, 2} <= set(P): -        m = [0, 0, 0] -        for x, y in zip(P, A): -            if x != 3: -                m[x] += y -        t = sum(abs(m - y) for m, y in zip(m, B)) -        l = sum(1 for j in P if j != 3) - 3 -        s = min(s, t + l * 10) -print(s) +N, A, B, C = list(map(int, input().split())) +L = [int(eval(input())) for n in range(N)] +ans = [] +for i in product(list(range(4)), repeat=N): +    a = 0 +    b = 0 +    c = 0 +    d = 0 +    for j in range(N): +        if i[j]: +            d += 1 +            if i[j] == 1: +                a += L[j] +            elif i[j] == 2: +                b += L[j] +            else: +                c += L[j] +    if a * b * c: +        ans += [abs(A - a) + abs(B - b) + abs(C - c) + 10 * (d - 3)] +print((min(ans)))