CodeEff/ECCO huggingface dataset:
# Original solution
N, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
used = [0]*N
global pattern
pattern = []
global ans
ans = float('inf')

def dfs(A):
    global pattern
    global ans
    if len(A) == N:
        pattern.append(A)
        ans = min(ans, MP(A))
        return
    
    for i in range(4):
        A.append(i)
        dfs(A)
        A.pop()

    return 

def MP(A):
    group1 = []
    group2 = []
    group3 = []
    for i in range(N):
        if A[i] == 1:
            group1 += [l[i]]
        elif A[i] == 2:
            group2 += [l[i]]
        elif A[i] == 3:
            group3 += [l[i]]
    if len(group1) == 0 or len(group2) == 0 or len(group3) == 0:
        return float('inf')

    return calc(group1, a)+calc(group2, b)+calc(group3, c)
    
def calc(group, length):
    res = float('inf')
    for i in range(2**len(group)):
        bag = []
        for j in range(len(group)):
            if (i>>j) & 1:
                bag += [group[j]]
        
        if len(bag) == 0:
            continue
        elif len(bag) == 1:
            res = min(res, abs(length - bag[0]))
        else:
            res = min(res, abs(length - sum(group)) + 10*(len(group)-1))
        
    return res

dfs([])
print(ans)


# Optimized solution

N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else float('inf')
    
    ret0 = dfs(cur+1, a, b, c)
    ret1 = dfs(cur+1, a+l[cur], b, c) + 10
    ret2 = dfs(cur+1, a, b+l[cur], c) + 10
    ret3 = dfs(cur+1, a, b, c+l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print((dfs(0, 0, 0, 0)))
# Original solution
import itertools

N,A,B,C=list(map(int,input().split()))
l=[int(eval(input())) for _ in range(N)]

d=list(itertools.product([0,1,2,3], repeat=N))

MIN=10**10
for i in range(len(d)):
    ans=0
    a_num=0
    b_num=0
    c_num=0
    a_kadomatu=A
    b_kadomatu=B
    c_kadomatu=C
    if {0,1,2} <= set(d[i]):
        for g in range(len(d[i])):
            if d[i][g]==0:
                a_num+=1
                a_kadomatu-=l[g]
            elif d[i][g]==1:
                b_num+=1
                b_kadomatu-=l[g]
            elif d[i][g]==2:
                c_num+=1
                c_kadomatu-=l[g]
        ans=abs(a_kadomatu)+abs(b_kadomatu)+abs(c_kadomatu)+10*(a_num-1)+10*(b_num-1)+10*(c_num-1)
        MIN=min(MIN,ans)
print(MIN)

# Optimized solution
def dfs(ka, kb, kc, cnta, cntb, cntc, phase):
    global ans
    if phase == n:
        if 0 < cnta and 0 < cntb and 0 < cntc:
            ans = min(ans, abs(a-ka) + abs(b-kb) + abs(c-kc) + 10*(cnta+cntb+cntc-3))
        return
    dfs(ka+l[phase], kb, kc, cnta+1, cntb, cntc, phase+1)
    dfs(ka, kb+l[phase], kc, cnta, cntb+1, cntc, phase+1)
    dfs(ka, kb, kc+l[phase], cnta, cntb, cntc+1, phase+1)
    dfs(ka, kb, kc, cnta, cntb, cntc, phase+1)


n,a,b,c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
ans = 10**9
dfs(0,0,0,0,0,0,0)
print(ans)
# Original solution
from itertools import product

N,a,b,c = list(map(int,input().split()))
L = list(int(eval(input())) for i in range(N))

ans = float("inf")

for prod in product(list(range(4)), repeat=N) :
    A = []
    B = []
    C = []
    D = []
    for i in range(len(prod)) :
        if prod[i] == 1 :
            A.append(L[i])
        elif prod[i] == 2 :
            B.append(L[i])
        elif prod[i] == 3 :
            C.append(L[i])
        else :
            D.append(L[i])
    if len(A) * len(B) * len(C) == 0 :
        continue
    cost = 0
    for li in [A,B,C] :
        cost += (len(li)-1)*10
    cost += abs(a-sum(A)) + abs(b-sum(B)) + abs(c-sum(C))
    
    ans = min(ans, cost)
print(ans)


# Optimized solution
from itertools import product

N,a,b,c = list(map(int,input().split()))
L = list(int(eval(input())) for i in range(N))

ans = float("inf")

for prod in product(list(range(4)), repeat=N) :
    A = []
    B = []
    C = []
    for i in range(len(prod)) :
        if prod[i] == 1 :
            A.append(L[i])
        elif prod[i] == 2 :
            B.append(L[i])
        elif prod[i] == 3 :
            C.append(L[i])
    
    if len(A) * len(B) * len(C) == 0 :
        continue
    cost = 0
    for li in [A,B,C] :
        cost += (len(li)-1)*10
    cost += abs(a-sum(A)) + abs(b-sum(B)) + abs(c-sum(C))
    ans = min(ans,cost)
print(ans)
# Original solution
class ans:
  def __init__(self):
    self.N, self.A, self.B, self.C = list(map(int,input().split()))
    self.L = [int(eval(input())) for _ in range(self.N)]
    print((self.dfs(0, 0, 0, 0)))
    exit()

  def dfs(self, x, a, b, c):
    if(x == self.N):
      if(min(a, b, c) > 0):
        return abs(a-self.A)+abs(b-self.B)+abs(c-self.C) - 30
      else:
        return 1e9+7
    ret0 = self.dfs(x+1, a, b, c)
    ret1 = self.dfs(x+1, a+self.L[x], b, c) + 10
    ret2 = self.dfs(x+1, a, b+self.L[x], c) + 10
    ret3 = self.dfs(x+1, a, b, c+self.L[x]) + 10
    return min(ret0, ret1, ret2, ret3)

ans()

# Optimized solution
N, A, B, C = list(map(int,input().split()))
L = [int(eval(input())) for _ in range(N)]

def dfs(x, a, b, c):
  if(x == N):
    if(min(a, b, c) > 0):
      return abs(a-A)+abs(b-B)+abs(c-C)-30
    else:
      return 1e9+7
  ret0 = dfs(x+1, a, b, c)
  ret1 = dfs(x+1, a+L[x], b, c) + 10
  ret2 = dfs(x+1, a, b+L[x], c) + 10
  ret3 = dfs(x+1, a, b, c+L[x]) + 10
  return min(ret0, ret1, ret2, ret3)
print((dfs(0, 0, 0, 0)))
# Original solution
n, *li = list(map(int, input().split()))
L = list(map(int, (int(eval(input())) for _ in range(n))))
ans = int(1e9)
def f(A, num, cnt):
    if num == n:
        if 0 in A:
            return
        global ans
        ans = min(ans, abs(A[0] - li[0]) + abs(A[1] - li[1]) + abs(A[2] - li[2]) + cnt)
        return
    for i in range(3):
        p = 0 if A[i] == 0 else 10
        B = A[::]
        B[i] += L[num]
        f(B, num + 1, cnt + p)
    f(A, num + 1, cnt)
f([0, 0, 0], 0, 0)
print(ans)


# Optimized solution
INF = float("inf")
n, A, B, C = list(map(int, input().split()))
L = tuple(map(int, (int(eval(input())) for _ in range(n))))
def f(a, b, c, num):
    if num == n:
        if min(a, b, c) > 0:
            return abs(A - a) + abs(B - b) + abs(C - c)
        else:
            return INF
    return min(
        f(a + L[num], b, c, num + 1) + (10 if a else 0),
        f(a, b + L[num], c, num + 1) + (10 if b else 0),
        f(a, b, c + L[num], num + 1) + (10 if c else 0),
        f(a, b, c, num + 1)
    )
print((f(0, 0, 0, 0)))
# Original solution
INF = float("inf")
n, A, B, C = list(map(int, input().split()))
L = tuple(map(int, (int(eval(input())) for _ in range(n))))
def f(a, b, c, num):
    if num == n:
        if min(a, b, c) > 0:
            return abs(A - a) + abs(B - b) + abs(C - c)
        else:
            return INF
    return min(
        f(a + L[num], b, c, num + 1) + (10 if a else 0),
        f(a, b + L[num], c, num + 1) + (10 if b else 0),
        f(a, b, c + L[num], num + 1) + (10 if c else 0),
        f(a, b, c, num + 1)
    )
print((f(0, 0, 0, 0)))


# Optimized solution
INF = float("inf")
n, A, B, C = list(map(int, input().split()))
L = tuple(map(int, (int(eval(input())) for _ in range(n))))
def f(a, b, c, num):
    if num == n:
        return abs(A - a) + abs(B - b) + abs(C - c) if min(a, b, c) > 0 else INF
    return min(
        f(a + L[num], b, c, num + 1) + (10 if a else 0),
        f(a, b + L[num], c, num + 1) + (10 if b else 0),
        f(a, b, c + L[num], num + 1) + (10 if c else 0),
        f(a, b, c, num + 1)
    )
print((f(0, 0, 0, 0)))
# Original solution
INF = float("inf")
n, A, B, C = list(map(int, input().split()))
L = tuple(map(int, (int(eval(input())) for _ in range(n))))
def f(a, b, c, num):
    if num == n:
        return abs(A - a) + abs(B - b) + abs(C - c) if min(a, b, c) > 0 else INF
    return min(
        f(a + L[num], b, c, num + 1) + (10 if a else 0),
        f(a, b + L[num], c, num + 1) + (10 if b else 0),
        f(a, b, c + L[num], num + 1) + (10 if c else 0),
        f(a, b, c, num + 1)
    )
print((f(0, 0, 0, 0)))


# Optimized solution
INF = int(1e9)
n, A, B, C = list(map(int, input().split()))
L = tuple(map(int, (int(eval(input())) for _ in range(n))))
def f(a, b, c, num):
    if num == n:
        return abs(A - a) + abs(B - b) + abs(C - c) if min(a, b, c) > 0 else INF
    return min(
        f(a + L[num], b, c, num + 1) + (10 if a else 0),
        f(a, b + L[num], c, num + 1) + (10 if b else 0),
        f(a, b, c + L[num], num + 1) + (10 if c else 0),
        f(a, b, c, num + 1)
    )
print((f(0, 0, 0, 0)))
# Original solution
import itertools

N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for i in range(N)]

def min_cost(target, l_list):
  if target in l_list:
    return 0
  else:
    res = 1000
    for l in l_list:
      res = min(res, abs(target - l))
    
    for i, l in enumerate(l_list):
      res = min(res, min_cost(target-l, l_list[:i]+l_list[i+1:]) + 10)
  
    return res

ans = 1000 * 3
combs = list(itertools.product([0, 1, 2], repeat=N))
for comb in combs:
  labc = [[], [], []]
  for i, idx in enumerate(comb):
    labc[idx].append(L[i])
  
  la, lb, lc = labc
  if len(la)*len(lb)*len(lc):
    ans = min(ans, min_cost(A, la)+min_cost(B, lb)+min_cost(C, lc))

print(ans)

# Optimized solution
import itertools

N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for i in range(N)]

def min_cost(target, l_list):
  return 10*(len(l_list) - 1) + abs(target - sum(l_list))


ans = 1000 * 3
combs = list(itertools.product([0, 1, 2, 3], repeat=N))
for comb in combs:
  labcn = [[], [], [], []]
  for i, idx in enumerate(comb):
    labcn[idx].append(L[i])
  
  la, lb, lc, ln = labcn
  if len(la)*len(lb)*len(lc):
    ans = min(ans, min_cost(A, la)+min_cost(B, lb)+min_cost(C, lc))

print(ans)
# Original solution
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)

# Optimized solution
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)
# Original solution
N,A,B,C = list(map(int,input().split()))
L = []
for i in range(N):
  L.append(int(eval(input())))
MP = float('inf')
n = 4  
def Base_10_to_n(X,n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n),n)+str(X%n)
  return str(X%n)

for X in range(4**N):
  STR = Base_10_to_n(X,n).zfill(N)
  nU = []
  uA = []
  uB = []
  uC = []
  SUBMP = 0
  for l in range(N):
    if STR[l] == '0':
      nU.append(L[l])
    elif STR[l] == '1':
      uA.append(L[l])
    elif STR[l] == '2':
      uB.append(L[l])
    else:
      uC.append(L[l])
    if len(uA) != 0 and len(uB) != 0 and len(uC) != 0:
      SUBMP = (len(uA)+len(uB)+len(uC)-3)*10+abs(sum(uA)-A)+abs(sum(uB)-B)+abs(sum(uC)-C)
      if SUBMP <= MP:
        MP = SUBMP
print(MP)

# Optimized solution
N,A,B,C = list(map(int,input().split()))
L = []
for i in range(N):
  L.append(int(eval(input())))
def Base_10_to_n(X,n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n),n)+str(X%n)
  return str(X%n)
n = 4
ans = float('inf')
for X in range(n**N):
  STR = Base_10_to_n(X,n).zfill(N)
  cur = 0
  TAKEA = 0
  TAKEB = 0
  TAKEC = 0
  for i in range(len(STR)):
    if STR[i] == '1':
      TAKEA += L[i]
      cur += 10
    elif STR[i] == '2':
      TAKEB += L[i]
      cur += 10
    elif STR[i] == '3':
      TAKEC += L[i]
      cur += 10
  if TAKEA != 0 and TAKEB != 0 and TAKEC != 0:
    cur += abs(TAKEA-A)+abs(TAKEB-B)+abs(TAKEC-C)
    cur -= 30
    if cur <= ans:
      ans = cur
print(ans)
# Original solution
N,A,B,C=list(map(int,input().split()))
L=[0]*N
for i in range(N):
  L[i]=int(eval(input()))

# ある竹を,Aに使う、Bに使う、Cに使う、どれにも使わない　の4パターンで全探索
# A,B,C	それぞれに対して2つ目以降は10Pかかる

stack=[]
# Aの長さ、Bの長さ、Cの長さ、処理した竹の本数、消費MP
stack.append([0,0,0,0,0])
ans=1000*10
while stack:
  a,b,c,num,mp=stack.pop()
  if num==N:
    if a==0 or b==0 or c==0:
      continue
    mp+=abs(A-a)+abs(B-b)+abs(C-c)
    if mp<ans:
      ans=mp
    continue
  for i in range(4):
    if i==0:
      stack.append([a+L[num],b,c,num+1,mp+(a!=0)*10])
    if i==1:
      stack.append([a,b+L[num],c,num+1,mp+(b!=0)*10])
    if i==2:
      stack.append([a,b,c+L[num],num+1,mp+(c!=0)*10])
    if i==3:
      stack.append([a,b,c,num+1,mp])
print(ans)

# Optimized solution
N,A,B,C=list(map(int,input().split()))
L=[0]*N
for i in range(N):
  L[i]=int(eval(input()))

# ある竹を,Aに使う、Bに使う、Cに使う、どれにも使わない　の4パターンで全探索
# A,B,C	それぞれに対して2つ目以降は10Pかかる

stack=[]
# Aの長さ、Bの長さ、Cの長さ、処理した竹の本数、消費MP
stack.append([0,0,0,0,0])
ans=1000*10
while stack:
  a,b,c,num,mp=stack.pop()
  if num==N:
    if a==0 or b==0 or c==0:
      continue
    mp+=abs(A-a)+abs(B-b)+abs(C-c)
    if mp<ans:
      ans=mp
    continue
  stack.append([a+L[num],b,c,num+1,mp+(a!=0)*10])
  stack.append([a,b+L[num],c,num+1,mp+(b!=0)*10])
  stack.append([a,b,c+L[num],num+1,mp+(c!=0)*10])
  stack.append([a,b,c,num+1,mp])
print(ans)
# Original solution
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

# def main():
  

# # main()
# print(main())

n,a,b,c=LI()
l=[I() for _ in range(n)]
answer=inf

def f(lst,ind):
  global answer
  if ind==n:
    ac=lst.count(1)
    bc=lst.count(2)
    cc=lst.count(3)

    if ac==0 or bc==0 or cc==0:
      return min(answer,inf)

    _a=_b=_c=0
    for i,x in enumerate(lst):
      if x==1:
        _a+=l[i]
      elif x==2:
        _b+=l[i]
      elif x==3:
        _c+=l[i]
    # 合わなかった原因。短縮できることを忘れてた
    # if _a>a or _b>b or _c>c:
    #   return min(answer,inf)

    sm=0
    sm+=max(0,ac-1)*10
    sm+=max(0,bc-1)*10
    sm+=max(0,cc-1)*10
    sm+=abs(a-_a)
    sm+=abs(b-_b)
    sm+=abs(c-_c)

    return min(answer,sm)

  else:
    for i in range(4):
      lst[ind]=i
      answer=min(answer,f(lst,ind+1))

  return answer

lst=[-1]*n
print((f(lst,0)))


# Optimized solution
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

n,a,b,c=LI()
l=[I() for _ in range(n)]

def dfs(cnt,aa,bb,cc):
  if cnt==n:
    if aa==0 or bb==0 or cc==0:
      return inf
    return abs(aa-a)+abs(bb-b)+abs(cc-c)-30

  aaa=dfs(cnt+1,aa+l[cnt],bb,cc)+10
  bbb=dfs(cnt+1,aa,bb+l[cnt],cc)+10
  ccc=dfs(cnt+1,aa,bb,cc+l[cnt])+10
  ddd=dfs(cnt+1,aa,bb,cc)
  return min(aaa,bbb,ccc,ddd)

print((dfs(0,0,0,0)))
# Original solution
from sys import setrecursionlimit
setrecursionlimit(1000000)

def permute(a, idx):
    if idx == len(a):
        permutations.append(a[::])
    for i in range(idx, len(a)):
        a[i], a[idx] = a[idx], a[i]
        permute(a, idx + 1)
        a[i], a[idx] = a[idx], a[i]

def doit(a, b, c, idx):
    if (a, b, c, idx) in memo:
        return memo[a, b, c, idx]
    if idx == len(unused):
        return abs(a - needA) + abs(b - needB) + abs(c - needC)
    memo[a, b, c, idx] = min(
        doit(a, b, c, idx + 1),
        doit(a + unused[idx], b, c, idx + 1) + 10,
        doit(a, b + unused[idx], c, idx + 1) + 10,
        doit(a, b, c + unused[idx], idx + 1) + 10
    )
    return memo[a, b, c, idx]

n, needA, needB, needC = list(map(int, input().split()))
a = [int(eval(input())) for _ in range(n)]
ret = float('inf')
for mask in range(1 << n):
    if bin(mask).count('1') != 3:
        continue
    abc = [a[i] for i in range(n) if (mask >> i) & 1]
    unused = [a[i] for i in range(n) if not (mask >> i) & 1]
    permutations = []
    permute(abc, 0)
    for p in permutations:
        memo = {}
        ret = min(ret, doit(p[0], p[1], p[2], 0))
print(ret)

# Optimized solution
from itertools import permutations
from sys import setrecursionlimit
setrecursionlimit(1000000)

def doit(a, b, c, idx):
    if (a, b, c, idx) in memo:
        return memo[a, b, c, idx]
    if idx == len(unused):
        return abs(a - needA) + abs(b - needB) + abs(c - needC)
    memo[a, b, c, idx] = min(
        doit(a, b, c, idx + 1),
        doit(a + unused[idx], b, c, idx + 1) + 10,
        doit(a, b + unused[idx], c, idx + 1) + 10,
        doit(a, b, c + unused[idx], idx + 1) + 10
    )
    return memo[a, b, c, idx]

n, needA, needB, needC = list(map(int, input().split()))
a = [int(eval(input())) for _ in range(n)]
ret = float('inf')
for mask in range(1 << n):
    if bin(mask).count('1') != 3:
        continue
    abc = [a[i] for i in range(n) if (mask >> i) & 1]
    unused = [a[i] for i in range(n) if not (mask >> i) & 1]
    for p in permutations(abc):
        memo = {}
        ret = min(ret, doit(p[0], p[1], p[2], 0))
print(ret)
# Original solution
import sys
from itertools import product

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = list(map(int, readline().split()))
    (*L,) = list(map(int, read().split()))

    ans = INF
    for p in product(list(range(4)), repeat=N):
        num = [0] * 3
        length = [0] * 3
        for i, j in enumerate(p):
            if j < 3:
                num[j] += 1
                length[j] += L[i]
        res = 0
        for j in range(3):
            if num[j] == 0:
                res = INF
                break
            else:
                res += (num[j] - 1) * 10 + abs(length[j] - A[j])
        if ans > res:
            ans = res

    print(ans)
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys
from itertools import product

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, B, C = list(map(int, readline().split()))
    (*L,) = list(map(int, read().split()))

    def rec(i, a, b, c):
        if i == N:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF

        res0 = rec(i + 1, a, b, c)
        res1 = rec(i + 1, a + L[i], b, c) + 10
        res2 = rec(i + 1, a, b + L[i], c) + 10
        res3 = rec(i + 1, a, b, c + L[i]) + 10

        return min(res0, res1, res2, res3)

    print((rec(0, 0, 0, 0)))
    return


if __name__ == '__main__':
    main()
# Original solution
n,A,B,C,=list(map(int,input().split()))
l=[int(eval(input())) for i in range(n)]
INF=1e9

def dfs(i,a,b,c):
  if i==n:
    if min(a,b,c)>0:
      return abs(A-a)+abs(B-b)+abs(C-c)-30
    else:
      return INF
  ret0 = dfs(i+1,a,b,c)
  ret1 = dfs(i+1,a+l[i],b,c)+10
  ret2 = dfs(i+1,a,b+l[i],c)+10
  ret3 = dfs(i+1,a,b,c+l[i])+10
  return min(ret0,ret1,ret2,ret3)
 
print((dfs(0,0,0,0)))

# Optimized solution
N,A,B,C=list(map(int,input().split()))
l=[int(eval(input())) for _ in range(N)]
inf=10**18
def dfs(cur,a,b,c):
  if cur==N:
    if min(a,b,c)>0:
      return abs(A-a)+abs(B-b)+abs(C-c)-30
    else:
      return inf
  res0 = dfs(cur+1,a,b,c)
  res1 = dfs(cur+1,a+l[cur],b,c)+10
  res2 = dfs(cur+1,a,b+l[cur],c)+10
  res3 = dfs(cur+1,a,b,c+l[cur])+10
  return min(res0,res1,res2,res3)
print((dfs(0,0,0,0)))
# Original solution
import itertools
N,A,B,C = list(map(int,input().split()))
l = [int(eval(input())) for i in range(N)]
inf = float('inf')
ans = inf
for pair in itertools.product(list(range(4)),repeat=N):
    mA = 0 ; mB = 0; mC = 0; cnt = 0
    for i in range(N):
        if pair[i] == 1:
            mA += l[i]
            cnt += 1
        elif pair[i] == 2:
            mB += l[i]
            cnt += 1
        elif pair[i] == 3:
            mC += l[i]
            cnt += 1
    if mA*mB*mC == 0:continue
    cost = abs(mA-A) + abs(mB-B) + abs(mC-C) + (cnt-3)*10
    if cost < ans:
        ans = cost
print(ans)

# Optimized solution
N,A,B,C = list(map(int,input().split()))
l = [int(eval(input())) for i in range(N)]
inf = float('inf')

def dfs(depth=0, a=0, b=0, c=0):
    if depth == N:
        if a*b*c != 0:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        return inf
    res0 = dfs(depth+1,a,b,c)
    res1 = dfs(depth+1,a+l[depth],b,c) + 10
    res2 = dfs(depth+1,a,b+l[depth],c) + 10
    res3 = dfs(depth+1,a,b,c+l[depth]) + 10
    return min([res0,res1,res2,res3])

print((dfs()))
# Original solution
N,A,B,C = list(map(int,input().split()))
l = [int(eval(input())) for i in range(N)]
inf = float('inf')

def dfs(depth=0, a=0, b=0, c=0):
    if depth == N:
        if a*b*c != 0:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        return inf
    res0 = dfs(depth+1,a,b,c)
    res1 = dfs(depth+1,a+l[depth],b,c) + 10
    res2 = dfs(depth+1,a,b+l[depth],c) + 10
    res3 = dfs(depth+1,a,b,c+l[depth]) + 10
    return min([res0,res1,res2,res3])

print((dfs()))

# Optimized solution
N,A,B,C = list(map(int,input().split()))
l = [int(eval(input())) for _ in range(N)]
ans = float('inf')
def dfs(d=0,a=0,b=0,c=0,mp=0):
    if d == N:
        mp = mp + abs(A-a) + abs(B-b) + abs(C-c) - 30
        global ans
        if a*b*c > 0 and mp < ans:
            ans = mp
        return
    dfs(d+1,a,b,c,mp)
    dfs(d+1,a+l[d],b,c,mp+10)
    dfs(d+1,a,b+l[d],c,mp+10)
    dfs(d+1,a,b,c+l[d],mp+10)

dfs()
print(ans)
# Original solution
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
inf = 10 ** 9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else inf
    non_marge = dfs(cur+1, a, b, c)
    marge_a = dfs(cur+1, a+L[cur], b, c) + 10
    marge_b = dfs(cur+1, a, b+L[cur], c) + 10
    marge_c = dfs(cur+1, a, b, c+L[cur]) + 10
    return min(non_marge, marge_a, marge_b, marge_c)

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

# Optimized solution
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
inf = 10**9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else inf
    no_merge = dfs(cur+1, a, b, c)
    merge_a = dfs(cur+1, a+L[cur], b, c) + 10
    merge_b = dfs(cur+1, a, b+L[cur], c) + 10
    merge_c = dfs(cur+1, a, b, c+L[cur]) + 10
    return min(no_merge, merge_a, merge_b, merge_c)

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