CodeEff/ECCO huggingface dataset:
# Original solution
# -*- coding: utf-8 -*-

import itertools
INF = 1e10

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

ans = INF
for prod in itertools.product('NABC', repeat=N):
    if not ('A' in prod and 'B' in prod and 'C' in prod):
        continue

    D = {'A': [], 'B': [], 'C': [], 'N': []}
    for i in range(N):
        D[prod[i]].append(L[i])

    tmp = max(len(D['A']) - 1, 0) * 10 + abs(sum(D['A']) - A)
    tmp += max(len(D['B']) - 1, 0) * 10 + abs(sum(D['B']) - B)
    tmp += max(len(D['C']) - 1, 0) * 10 + abs(sum(D['C']) - C)
    ans = min(ans, tmp)

print(ans)


# Optimized solution
# -*- coding: utf-8 -*-

import itertools
INF = 1e10

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

ans = INF
for prod in itertools.product('NABC', repeat=N):
    if not ('A' in prod and 'B' in prod and 'C' in prod):
        continue

    D = {'A': [], 'B': [], 'C': [], 'N': []}
    for i in range(N):
        D[prod[i]].append(L[i])

    tmp = (len(D['A']) - 1) * 10 + abs(sum(D['A']) - A)
    tmp += (len(D['B']) - 1) * 10 + abs(sum(D['B']) - B)
    tmp += (len(D['C']) - 1) * 10 + abs(sum(D['C']) - C)
    ans = min(ans, tmp)

print(ans)
# Original solution
from itertools import product
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    inf=10**16
    n,*abc=MI()
    ll=[II() for _ in range(n)]

    ans=inf
    for pp in product(range(4),repeat=n):
        ss=[0]*3
        cnt=[0]*3
        for l,p in zip(ll,pp):
            if p==3:continue
            ss[p]+=l
            cnt[p]+=1
        cur=0
        for i in range(3):
            if cnt[i]==0:
                cur=inf
                break
            cur+=(cnt[i]-1)*10+abs(abc[i]-ss[i])
        #print(pp,cur)
        ans=min(ans,cur)

    print(ans)

main()


# Optimized solution
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    inf=10**9
    n,*abc=MI()
    abc.sort()
    a,b,c=abc
    dp={(0,0,0):0}
    for _ in range(n):
        l=II()
        ndp={}
        for xyz,s in dp.items():
            ndp.setdefault(xyz,inf)
            ndp[xyz]=min(ndp[xyz],s)
            for i in range(3):
                nx=list(xyz)
                ns=s+10 if nx[i] else s
                nx[i]+=l
                t=tuple(sorted(nx))
                ndp.setdefault(t,inf)
                ndp[t]=min(ndp[t],ns)
            dp=ndp

    ans=inf
    for (x,y,z),s in dp.items():
        if x*y*z==0:continue
        cur=abs(x-a)+abs(y-b)+abs(z-c)+s
        ans=min(ans,cur)

    print(ans)

main()
# Original solution
from itertools import*
n,a,b,c,*l=list(map(int,open(0).read().split()))
d=[a,b,c]
ans=float("inf")
for i in product(list(range(4)),repeat=n):
    take=[[],[],[]]
    for k,j in enumerate(i):  #0を捨てる
        if j!=0:
            take[j-1].append(l[k])
    if all(take):
        take2=list(map(sum,take))
        #print(sum(abs(s-t)for s,t in zip(d,take2)),(sum(map(len,take))-3)*10)
        ans=min(ans,sum(abs(s-t)for s,t in zip(d,take2))+(sum(map(len,take))-3)*10)
print(ans)

# Optimized solution
from itertools import*
n,a,b,c,*l=list(map(int,open(0).read().split()))
ans=float("inf")
for i in product(list(range(4)),repeat=n): #3を捨てる
    take=[[],[],[]]
    for k,j in enumerate(i):
        if j==3:
            continue
        take[j].append(l[k])
    *tmp,=list(map(len,take))
    if all(tmp):
        x,y,z=list(map(sum,take))
        ans=min(ans, (sum(tmp)-3)*10 + abs(x-a) + abs(y-b) + abs(z-c) )
print(ans)
# Original solution
import itertools

N,A,B,C = list(map(int,input().split()))
comb = [] #0:使用しない,1:竹Aの材料,2:竹Bの材料,3:竹Cの材料
L = []
for i in range(N):
  l = int(eval(input()))
  L.append(l)
  comb.append([0,1,2,3])

All_comb =  list(itertools.product(*comb))
min_MP = float('inf')
for i in range(len(All_comb)):
  tmp = All_comb[i]
  Non_material = []
  A_material = []
  B_material = []
  C_material = []
  for j in range(len(tmp)):
    if(tmp[j] == 0): Non_material.append(L[j])
    elif(tmp[j] == 1): A_material.append(L[j])
    elif(tmp[j] == 2): B_material.append(L[j])
    elif(tmp[j] == 3): C_material.append(L[j])
    a,b,c = len(A_material),len(B_material),len(C_material)
    if((a>=1)and(b>=1)and(c>=1)):
     sum_A,sum_B,sum_C = sum(A_material),sum(B_material),sum(C_material)
     MP = abs(A-sum_A)+abs(B-sum_B)+abs(C-sum_C) +10*(a+b+c-3)
     min_MP = min(MP,min_MP)

print(min_MP)
    

# Optimized solution
import itertools

N,A,B,C = list(map(int,input().split()))
Comb = itertools.product([0,1,2,3],repeat=N)

L = []
for i in range(N):
  l = int(eval(input()))
  L.append(l)
  
# 各竹について  
# 0 : 使用しない
# 1 : 竹Aの材料にする  
# 2 : 竹Bの材料にする 
# 3 : 竹Cの材料にする
# 竹A,B,Cの作成法 :
# とりあえず全部合成 → 目的の長さに合わせる

ans = float('inf')
for X in Comb:
  tmp = 0
  m_A,m_B,m_C = [],[],[]
  for i in range(N):
    if(X[i] == 1): m_A.append(L[i])
    elif(X[i] == 2): m_B.append(L[i])
    elif(X[i] == 3): m_C.append(L[i])
  # 空の竹リストがないなら    
  if(len(m_A)*len(m_B)*len(m_C) != 0):      
    for take_list,take_len in zip([m_A,m_B,m_C],[A,B,C]):
      tmp += (len(take_list)-1)*10 # 合成
      tmp += (abs(take_len-sum(take_list)))*1 # 延長or短縮
    ans = min(ans,tmp)
  
print(ans)
# Original solution
import itertools
n,a,b,c=(list(map(int,input().split())))
l=[int(eval(input())) for i in range(n)]
ans=10**9
for k in itertools.product(list(range(4)),repeat=n):
    A=[[] for i in range(4)]
    for i in range(n):
        A[k[i]]+=[l[i]]
    if A[1] and A[2] and A[3]:
        tmp=10*(n-len(A[0])-3)
        tmp+=abs(a-sum(A[1]))
        tmp+=abs(b-sum(A[2]))
        tmp+=abs(c-sum(A[3]))
        ans=min(tmp,ans)
print(ans)

# Optimized solution
N,A,B,C=list(map(int,input().split()))
l=[int(eval(input())) for i 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
  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
n, A, B, C = (int(i) for i in input().split())
l = [int(eval(input())) for i in range(n)]
a = []
b = []
c = []

def furiwake(x):
    global a
    global b
    global c
    a = []
    b = []
    c = []
    for i in range(1, n+1):
        if dig4(x, i) == 0:
            a.append(l[i-1])
        if dig4(x, i) == 1:
            b.append(l[i-1])
        if dig4(x, i) == 2:
            c.append(l[i-1])

def dig4(n, k):
    return (n%(4**k))//(4**(k-1))

def cost():
    costa = 10 * (len(a)-1) + abs(sum(a)-A)
    costb = 10 * (len(b)-1) + abs(sum(b)-B)
    costc = 10 * (len(c)-1) + abs(sum(c)-C)
    return costa+costb+costc

ans = 1000000000
for i in range(1, 4**8):
    furiwake(i)
    if(len(a)*len(b)*len(c)):
        ans = min(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 = 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
	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
from itertools import product
from collections import Counter as ct

n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]

ans = 10 ** 10
for bit in product([0, 1, 2, 3], repeat=n):
    if len(set(bit) - {0}) != 3:
        continue
    tmpa = 0
    tmpb = 0
    tmpc = 0
    for i, j in enumerate(bit):
        if j == 1:
            tmpa += l[i]
        elif j == 2:
            tmpb += l[i]
        elif j == 3:
            tmpc += l[i]
    mp = abs(a - tmpa) + abs(b - tmpb) + abs(c - tmpc)
    tmp = ct(bit)
    for i in range(1, 4):
        mp += max(0, tmp[i] - 1) * 10
    ans = min(ans, mp)
print(ans)

# Optimized solution
from itertools import product

n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]

ans = 10 ** 10
for bit in product([0, 1, 2, 3], repeat=n):
    tmp = [0] * 4
    mp = 0
    for i, j in enumerate(bit):
        if j != 3 and tmp[j] != 0:
            mp += 10
        tmp[j] += l[i]
    if any([i == 0 for i in tmp[:3]]):
        continue
    mp += abs(a - tmp[0]) + abs(b - tmp[1]) + abs(c - tmp[2])
    ans = min(ans, mp)
print(ans)
# Original solution
from itertools import product

n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]

ans = 10 ** 10
for bit in product([0, 1, 2, 3], repeat=n):
    tmp = [0] * 4
    mp = 0
    for i, j in enumerate(bit):
        if j != 3 and tmp[j] != 0:
            mp += 10
        tmp[j] += l[i]
    if any([i == 0 for i in tmp[:3]]):
        continue
    mp += abs(a - tmp[0]) + abs(b - tmp[1]) + abs(c - tmp[2])
    ans = min(ans, mp)
print(ans)


# Optimized solution
# dfs版
def dfs(d, A, B, C, f):
    global ans
    if d == n:
        if not 0 in [A, B, C]:
            ans = min(ans, abs(a - A) + abs(b - B) + abs(c - C) + f - 30)
        return
    dfs(d + 1, A, B, C, f)
    dfs(d + 1, A + l[d], B, C, f + 10)
    dfs(d + 1, A, B + l[d], C, f + 10)
    dfs(d + 1, A, B, C + l[d], f + 10)


n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
ans = 10 ** 10
dfs(0, 0, 0, 0, 0)
print(ans)
# Original solution
# ABC119C
# Synthetic Kadomatsu
Enter = list(map(int, input().split()))
N = Enter[0]
L = [int(eval(input())) for _ in range(N)]

ans = 10 ** 10

# 4 bist search
for i in range(4**N):
    mask = i
    NowCost = 0
    Group = [[] * 4 for _ in range(4)]
    for j in range(N-1, -1, -1):
        Group[mask%4].append(L[j])
        mask //= 4
    if len(Group[0]) == 0 or len(Group[1]) == 0 or len(Group[2]) == 0:
        continue
    for j in range(3):
        NowCost += 10 * (len(Group[j]) - 1)
        NowCost += abs(sum(Group[j]) - Enter[j+1])
    ans = min(ans, NowCost)
print(ans)


# 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:
        if min(a, b, c) > 0:
            return abs(a-A)+abs(b-B)+abs(c-C)-30
        else:
            return INF
    ret1 = dfs(cur+1, a, b, c)
    ret2 = dfs(cur+1, a+L[cur], b, c) + 10
    ret3 = dfs(cur+1, a, b+L[cur], c) + 10
    ret4 = dfs(cur+1, a, b, c+L[cur]) + 10
    return min(ret1, ret2, ret3, ret4)

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)]
L_perm = list(itertools.permutations(L))
ans = 10**9
for l in L_perm:
    for i in range(1, n-1):
        A_tree = l[:i]
        synthesis_A = 10 * (i-1)
        fix_A = abs(a-sum(A_tree))
        for j in range(i+1, n):
            B_tree = l[i:j]
            synthesis_B = 10 * (j-i-1)
            fix_B = abs(b-sum(B_tree))
            for k in range(j+1, n+1):
                C_tree = l[j:k]
                synthesis_C = 10 * (k-j-1)
                fix_C = abs(c-sum(C_tree))

                total = fix_A + fix_B + fix_C + synthesis_A + synthesis_B + synthesis_C
                ans = min(ans, total)

print(ans)

# Optimized solution
import itertools


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

for pattern in itertools.product(list(range(4)), repeat=N):
    if not {1, 2, 3} <= set(pattern):
        continue

    trees = [0] * 3
    synthesis_cost = -30
    for num, length in zip(pattern, L):
        if num == 0:
            continue
        trees[num-1] += length
        synthesis_cost += 10

    fix_cost = 0
    for tree_length, target_length in zip(trees, [A, B, C]):
        fix_cost += abs(target_length - tree_length)

    total_cost = synthesis_cost + fix_cost
    ans = min(ans, total_cost)

print(ans)
# Original solution
#!/usr/bin/env python3
import sys

INF = 10**9


def dfs(cur, l, ia, ib, ic):
    if(cur == N):
        return abs(ia-A) + abs(ib-B) + abs(ic-C) - 30 if min(ia,ib,ic) > 0 else INF

    ret0 = dfs(cur+1, l, ia, ib, ic)
    ret1 = dfs(cur+1, l, ia+l[cur], ib, ic) + 10
    ret2 = dfs(cur+1, l, ia, ib+l[cur], ic) + 10
    ret3 = dfs(cur+1, l, ia, ib, ic+l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)


def solve(N: int, A: int, B: int, C: int, l: "List[int]"):
    print((dfs(0,l,0,0,0)))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    global N, A, B, C, l
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    l = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A, B, C, l)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys

INF = 10**9


def dfs(cur, ia, ib, ic):
    if(cur == N):
        return abs(ia-A) + abs(ib-B) + abs(ic-C) - 30 if min(ia,ib,ic) > 0 else INF

    ret0 = dfs(cur+1, ia, ib, ic)
    ret1 = dfs(cur+1, ia+l[cur], ib, ic) + 10
    ret2 = dfs(cur+1, ia, ib+l[cur], ic) + 10
    ret3 = dfs(cur+1, ia, ib, ic+l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)


def solve(N: int, A: int, B: int, C: int, l: "List[int]"):
    print((dfs(0,0,0,0)))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    global N, A, B, C, l
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    l = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A, B, C, l)

if __name__ == '__main__':
    main()
# Original solution
n, a, b, c = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(n)]
targets = [a, b, c]

ans = 10**9
from itertools import product
for comb in product([0, 1, 2, 3], repeat=n):
    if len(set(comb)) in [1, 2]:
        continue
    # a, b, c
    ls = [[], [], []]
    for i, c in enumerate(comb):
        if c == 3:
            continue
        ls[c].append(L[i])

    mps = 0
    for idx, ll in enumerate(ls):
        if len(ll) == 0:
            break
        tmp = (len(ll)-1)*10
        mps += tmp
        mps += abs(targets[idx] - sum(ll))
    else:
        ans = min(ans, mps)
    
print(ans)


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

def rec(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
    ret0 = rec(cur+1, a, b, c)
    ret1 = rec(cur+1, a+L[cur], b, c) + 10
    ret2 = rec(cur+1, a, b+L[cur], c) + 10
    ret3 = rec(cur+1, a, b, c+L[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print((rec(0, 0, 0, 0)))
# Original solution
N, A, B, C = list(map(int, input().split()))
L = []
for _ in range(N):
    L.append(int(eval(input())))

ans = float('inf')
for mask in range(pow(4, N)):
    cost = 0
    for i, l in enumerate([A, B, C]):
        grp = []
        for digit in range(N):
            if mask // pow(4, digit) % 4 == i:
                grp.append(L[digit])

        if not grp:
            cost = float('inf')

        cost += (len(grp) - 1) * 10
        cost += abs(l - sum(grp))
    ans = min(ans, cost)

print(ans)

# Optimized solution
from itertools import product

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

ans = 10**18
for state in product(list(range(4)), repeat=N):
    K = [[] for _ in range(4)]
    for i, l in enumerate(L):
        K[state[i]].append(l)

    cost = 0
    for d, D in zip((A, B, C), K):
        if len(D) == 0:
            cost += 10**18
        cost += (len(D) - 1) * 10
        cost += abs(d - sum(D))
    ans = min(ans, cost)

print(ans)
# Original solution
n,a,b,c = list(map(int,input().split()))
L = []
for i in range(n):
    L.append(int(eval(input())))
import itertools
ans = 10**9
tmp = 0
for perm in itertools.permutations(list(range(n)),3):
    ua,ub,uc = perm
    la,lb,lc = L[ua],L[ub],L[uc]
    for use in itertools.product([0,1,2,-1] ,repeat=n-3):
        idx = 0
        tmp = 0
        ls = [la,lb,lc]
        for i,l in enumerate(L):
            if i== ua or  i== ub or i== uc:
                continue
            else:
                if use[idx]>-1:
                    ls[use[idx]] +=l
                    tmp+=10
            idx+=1
        tmp = tmp + abs(ls[0] -a) +abs(ls[1] -b)+abs(ls[2] -c)
        ans=min(ans,tmp)
print(ans)


# Optimized solution
n,a,b,c = list(map(int,input().split()))
L = []
for i in range(n):
    L.append(int(eval(input())))
import itertools
ans = 10**9
tmp = 0
for use in itertools.product([0,1,2,-1] ,repeat=n):
    tmp = 0
    ls = [0,0,0]
    for idx,u in enumerate(use):
        if u>-1:
            if ls[u] >0:
                tmp+=10
            ls[u]+=L[idx]

    if ls[0] ==0 or ls[1] ==0 or ls[2] ==0:continue
    tmp = tmp + abs(ls[0] -a) +abs(ls[1] -b)+abs(ls[2] -c)
    ans = min(tmp,ans)
print(ans)
# Original solution
N,A,B,C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]

INF = 1<<20
score = INF

import itertools
for ms in itertools.product(list(range(-1,3)), repeat=N):
    lens = [0]*3
    tmp_score = -30
    for i, group in enumerate(ms):
        if group>=0:
            lens[group] += l[i]
            tmp_score += 10
    if all(lens):
        score = min(score, tmp_score + abs(lens[0]-A)+abs(lens[1]-B)+abs(lens[2]-C))

print(score)


# Optimized solution
def main():
    N,A,B,C = list(map(int, input().split()))
    l = [int(eval(input())) for _ in range(N)]
    
    INF = 1<<20
    
    def perm(n, a, b, c):
        if n == N:
            if all([a, b, c]):
                return abs(A-a)+abs(B-b)+abs(C-c)-30
            else:
                return INF
        return min(
            perm(n+1,a,b,c),
            perm(n+1,a+l[n],b,c)+10,
            perm(n+1,a,b+l[n],c)+10,
            perm(n+1,a,b,c+l[n])+10
            )
    
    print((perm(0,0,0,0)))

main()
# Original solution
N, A, B, C = [int(a) for a in input().split(" ")]
ls = [int(eval(input())) for i in range(N)]
tab = [([float("inf")]*N, ref) for ref in (A, B, C)]
INF = float("inf")
from heapq import heappush, heappop, heapreplace
maxtarg = max(A, B, C)

# O(n)
def solve(ls):
    n = len(ls)
    qs = [[(-INF, -1)]*3 for i in range(3)]
    # 3*n times
    for ref, q in zip((A, B, C), qs):
        for i in range(n):
            val = -abs(ref-ls[i])
            if q[0][0] < val:
                heapreplace(q, (val, i))
    ans = INF
    # 9 times
    for a, i in qs[0]:
        for b, j in qs[1]:
            for c, k in qs[2]:
                if i!=j and j!=k and k!=i:
                    ans = min(ans, -(a+b+c))
    return ans

def dfs(ls):
    n = len(ls)
    if n < 3: return INF
    ans = solve(ls)
    for i in range(n-1):
        for j in range(i+1,n):
            tmp = ls[i]+ls[j]
            if min(maxtarg-ls[i], maxtarg-ls[j]) < 10:
                continue
            ls2 = ls[:i]+ls[i+1:]
            ls2[j-1] = tmp
            ans = min(ans, 10+dfs(ls2))
    return ans

print((dfs(ls)))


# Optimized solution
N, A, B, C = [int(a) for a in input().split(" ")]
ls = [int(eval(input())) for i in range(N)]
tab = [([float("inf")]*N, ref) for ref in (A, B, C)]
INF = float("inf")
from heapq import heappush, heappop, heapreplace
maxtarg = max(A, B, C)

# O(n)
def solve(ls):
    n = len(ls)
    qs = [[(-INF, -1)]*3 for i in range(3)]
    # 3*n times
    for ref, q in zip((A, B, C), qs):
        for i in range(n):
            val = -abs(ref-ls[i])
            if q[0][0] < val:
                heapreplace(q, (val, i))
    ans = INF
    # 9 times
    for a, i in qs[0]:
        for b, j in qs[1]:
            for c, k in qs[2]:
                if i!=j and j!=k and k!=i:
                    ans = min(ans, -(a+b+c))
    return ans
dic = {}
def dfs(ls):
    key = tuple(sorted(ls))
    if key in dic:
        return dic[key]
    n = len(ls)
    if n < 3: return INF
    ans = solve(ls)
    for i in range(n-1):
        for j in range(i+1,n):
            tmp = ls[i]+ls[j]
            if min(maxtarg-ls[i], maxtarg-ls[j]) < 10:
                continue
            ls2 = ls[:i]+ls[i+1:]
            ls2[j-1] = tmp
            ans = min(ans, 10+dfs(ls2))
    dic[key] = ans
    return ans

print((dfs(ls)))
# Original solution
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,a,b,c=list(map(int,input().split()))
    L=[int(eval(input())) for _ in range(n)]

    def dfs(v,Idx)->int:
        # terminate condition
        if(v==n):
            score=0
            Idx=tuple(Idx)
            A,B,C=[],[],[]
            for i,k in enumerate(Idx):
                if(k==0): A.append(L[i])
                elif(k==1): B.append(L[i])
                elif(k==2): C.append(L[i])
            if((not A) or (not B) or (not C)): return INF # 1つも竹が無いのはダメ
            score+=(len(A)+len(B)+len(C)-3)*10

            SA=sum(A)
            SB=sum(B)
            SC=sum(C)
            score+=abs(SA-a)
            score+=abs(SB-b)
            score+=abs(SC-c)

            return score

        res=INF
        for i in range(4):
            res=min(res,dfs(v+1,Idx+[i]))
        return res

    print((dfs(0,[])))
resolve()

# Optimized solution
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,a,b,c=list(map(int,input().split()))
    L=[int(eval(input())) for _ in range(n)]

    def dfs(v,Idx)->int:
        # terminate condition
        if(v==n):
            score=0
            Idx=tuple(Idx)
            A,B,C=[],[],[]
            for i,k in enumerate(Idx):
                if(k==0): A.append(L[i])
                elif(k==1): B.append(L[i])
                elif(k==2): C.append(L[i])
            if((not A) or (not B) or (not C)): return INF # 1つも竹が無いのはダメ
            score+=(len(A)+len(B)+len(C)-3)*10

            SA=sum(A)
            SB=sum(B)
            SC=sum(C)
            score+=abs(SA-a)
            score+=abs(SB-b)
            score+=abs(SC-c)
            return score
            
        res=INF
        for i in range(4):
            Idx[v]=i
            res=min(res,dfs(v+1,Idx))
        return res

    print((dfs(0,[0]*n)))
resolve()