CodeEff/ECCO huggingface dataset:
# Original solution
N, A, B, C= list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]

K = 4

minmp = 1e8
for x in range(pow(4, N)):
    v = x
    c = [0] * K
    s = [0] * K
    i = 0
    while v > 0:
        m = v % K
        c[m] += 1
        s[m] += L[i]
        i += 1
        v //= K

    if c[1] > 0 and c[2] > 0 and c[3] > 0:
        minmp = min(minmp, (c[1] + c[2] + c[3] - 3) * 10 + abs(s[1] - A) + abs(s[2] - B) + abs(s[3] - C))

print(minmp)


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

mp = sum(P) - 30

minmp = 1e10
Pcnt = [0] * 3
Ks = [-1] * N

while True:

    i = N-1
    while i >= 0:
        pre = cur = Ks[i]
        cur += 1
        if cur >= 3:
            cur = -1
        Ks[i] = cur

        for d, x in ((-1, pre), (1, cur)):

            if x >= 0:
                Pcnt[x] += d
                mp -= abs(P[x])
                P[x] -= d * L[i]
                mp += abs(P[x]) + d * 10

        if cur >= 0:
            break
        i -= 1
    else:
        break

    if min(Pcnt) > 0:
        minmp = min(minmp, mp)

print(minmp)
# Original solution
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy

N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
ans = 10**20
for use in it.product({0, 1, 2, 3}, repeat=N):
    ABC = {0: [], 1: [], 2: [], 3: []}
    for i, u in enumerate(use):
        dump(i, u, use)
        ABC[u].append(l[i])
    if any([len(ABC[u]) == 0 for u in {1, 2, 3}]):
        continue
    ans = min(ans, sum([abs(sum(ABC[i]) - x) + (len(ABC[i]) - 1)
                        * 10 for i, x in zip([1, 2, 3], [A, B, C])]))
print(ans)


# Optimized solution
n, a, b, c = [int(it) for it in input().split()]
ls = [int(eval(input())) for it in range(n)]
def dfs(cur, tmpA, tmpB, tmpC):
    if cur == n:
        return abs(a - tmpA) + abs(b - tmpB) + abs(c - tmpC) if tmpA > 0 and tmpB > 0 and tmpC else 10**20
    return min(
        dfs(cur + 1, tmpA + ls[cur], tmpB, tmpC) + (10 if tmpA > 0 else 0),
        dfs(cur + 1, tmpA, tmpB + ls[cur], tmpC) + (10 if tmpB > 0 else 0),
        dfs(cur + 1, tmpA, tmpB, tmpC + ls[cur]) + (10 if tmpC > 0 else 0),
        dfs(cur + 1, tmpA, tmpB, tmpC)
    )

print((dfs(0, 0, 0, 0)))
# Original 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)))

# 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 a * b * c != 0 else 10 ** 9
    else:
        ret0 = dfs(cur + 1, a, b, c)
        reta = dfs(cur + 1, a + l[cur], b, c) + 10
        retb = dfs(cur + 1, a, b + l[cur], c) + 10
        retc = dfs(cur + 1, a, b, c + l[cur]) + 10
        return min(ret0, reta, retb, retc)
print((dfs(0,0,0,0)))
# Original solution
from itertools import combinations

def f(in_A,in_B,in_C,A,B,C,ex_l,counter):
    if (counter == len(ex_l)):
        return abs(in_A-A)+abs(in_B-B)+abs(in_C-C)
    else:
        tmp = ex_l[counter]
        counter +=1
        a1 = f(in_A+tmp,in_B,in_C,A,B,C,ex_l,counter)+10
        a2 = f(in_A,in_B+tmp,in_C,A,B,C,ex_l,counter)+10
        a3 = f(in_A,in_B,in_C+tmp,A,B,C,ex_l,counter)+10
        a4 = f(in_A,in_B,in_C,A,B,C,ex_l,counter)
    return min(a1,a2,a3,a4)

N,A,B,C=list(map(int,input().split()))
l = []
for i in range(N):
    l.append(int(eval(input())))
in_l = list(map(list,combinations(l,3)))
ex_l = [l[:] for _ in range(len(in_l))]
for i in range(len(in_l)):
    ex_l[i].remove(in_l[i][0])
    ex_l[i].remove(in_l[i][1])
    ex_l[i].remove(in_l[i][2])

mp = []
for i in range(len(in_l)):
    mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],A,B,C,ex_l[i],0))
    mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],A,C,B,ex_l[i],0))
    mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],B,A,C,ex_l[i],0))
    mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],B,C,A,ex_l[i],0))
    mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],C,A,B,ex_l[i],0))
    mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],C,B,A,ex_l[i],0))
mp = min(mp)
print(mp)

# Optimized solution
n,a,b,c = list(map(int,input().split()))
l = []
ans = []
for i in range(n):
    l.append(int(eval(input())))

def f(x,y,z,arr,ca,cb,cc):
    global a
    global b
    global c
    global ans
    if arr:
        f(x + arr[0], y, z, arr[1:],ca+1,cb,cc)
        f(x, y + arr[0], z, arr[1:],ca,cb+1,cc)
        f(x, y, z + arr[0], arr[1:],ca,cb,cc+1)
        f(x, y, z, arr[1:],ca,cb,cc)
    else:
        if x > 0 and y > 0 and z > 0:
            ans.append(abs(a-x) + abs(b-y) + abs(c-z) + 10 * (ca + cb + cc - 3))
f(0,0,0,l,0,0,0)
print((min(ans)))
# Original solution
n,a,b,c = list(map(int,input().split()))
l = []
ans = []
for i in range(n):
    l.append(int(eval(input())))

def f(x,y,z,arr,ca,cb,cc):
    global a
    global b
    global c
    global ans
    if arr:
        f(x + arr[0], y, z, arr[1:],ca+1,cb,cc)
        f(x, y + arr[0], z, arr[1:],ca,cb+1,cc)
        f(x, y, z + arr[0], arr[1:],ca,cb,cc+1)
        f(x, y, z, arr[1:],ca,cb,cc)
    else:
        if x > 0 and y > 0 and z > 0:
            ans.append(abs(a-x) + abs(b-y) + abs(c-z) + 10 * (ca + cb + cc - 3))
f(0,0,0,l,0,0,0)
print((min(ans)))

# Optimized solution
n,a,b,c = list(map(int,input().split()))
l = []
ans = []
for i in range(n):
    l.append(int(eval(input())))

def f(x,y,z,arr,cnt):
    global a
    global b
    global c
    global ans
    if arr:
        f(x + arr[0], y, z, arr[1:],cnt+1)
        f(x, y + arr[0], z, arr[1:],cnt+1)
        f(x, y, z + arr[0], arr[1:],cnt+1)
        f(x, y, z, arr[1:],cnt)
    else:
        if x > 0 and y > 0 and z > 0:
            ans.append(abs(a-x) + abs(b-y) + abs(c-z) + 10 * (cnt - 3))
f(0,0,0,l,0)
print((min(ans)))
# Original solution
from itertools import product
import bisect

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

ll = []
for _ in range(N):
    ll.append(int(eval(input())))



ans = 10**8
ite = product(list(range(4)),repeat=N)
for pattern in ite:
    bag = [[],[],[]]
    singles = []
    mp = 0
    for i, p in enumerate(pattern):
        if p == 3: singles.append(ll[i])
        else: bag[p].append(ll[i])
    
    zero_cnt = 0
    for b in bag:
        if not b: zero_cnt+=1
        else: mp += (len(b)-1)*10
    if not singles: zero_cnt+=1
    if zero_cnt >= 2: continue

    bamboos = []
    for b in bag:
        if b: bamboos.append(sum(b))
    for s in singles:
        bamboos.append(s)

    bamboos.sort()
    # print(bamboos)
    
    for t in tl:
        curr_min = 10000
        curr_min_i = 0
        for i, ba in enumerate(bamboos):
            if abs(ba - t) < curr_min:
                curr_min = abs(ba-t)
                curr_min_i = i
        mp += curr_min
        bamboos.pop(curr_min_i)

    ans = min(ans,mp)

print(ans)

# Optimized solution

from itertools import product

def main():
    n,a,b,c = list(map(int, input().split()))
    targetl = [a,b,c]
    targetl.sort()
    ll = []
    for _ in range(n):
        l = int(eval(input()))
        ll.append(l)

    ans = 10**9
    ite = product(list(range(4)),repeat=n)
    ite = list(ite)
    for it in ite:
        bamboosl = [ [],[],[] ]
        cost = -30
        for i,v in enumerate(it):
            if v != 3:
                bamboosl[v].append(ll[i])
                cost += 10

        continue_f = False    
        for bamboos in bamboosl:
            if not bamboos: continue_f = True
        if continue_f: continue

        longs = []
        for bamboos in bamboosl:
            curr_l = sum(bamboos)
            longs.append(curr_l)
        longs.sort()

        for v1,v2 in zip(targetl,longs):
            cost += abs(v1-v2)
            
        ans = min(ans,cost)

    print(ans)


if __name__ == "__main__":
    main()
# Original solution
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)

def f(a,A):
    if len(a) == 0:
        return 1e12
    return (len(a)-1)*10 + abs(sum(a)-A)

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

ans = 1e12
for i in range(4**N+1):
    tmp = list(base_10_to_n(i,4).zfill(N))
    a,b,c = [],[],[]
    for s,t in zip(tmp,l):
        if s == "1":
            a.append(t)
        elif s == "2":
            b.append(t)
        elif s == "3":
            c.append(t)
    ans = min(ans,f(a,A)+f(b,B)+f(c,C))

print(ans)
        

# Optimized solution
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)

def f(a,la,A):
    if la == 0:
        return 1e12
    return (la-1)*10 + abs(a-A)

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

ans = 1e12
for i in range(4**N+1):
    tmp = list(base_10_to_n(i,4).zfill(N))
    a,la,b,lb,c,lc = 0,0,0,0,0,0
    for s,t in zip(tmp,l):
        if s == "1":
            a += t
            la += 1
        elif s == "2":
            b += t
            lb += 1
        elif s == "3":
            c += t
            lc += 1
    ans = min(ans,f(a,la,A)+f(b,lb,B)+f(c,lc,C))

print(ans)
# Original solution
import sys

#+++++


def aaa(ll,a,b,c):
	ret=a+b+c
	for i,v1 in enumerate(ll):
		if v1==0:
			continue
		t1=abs(a-v1)
		if ret < t1:
			continue
		for j,v2 in enumerate(ll):
			if v2==0:
				continue
			if i==j:
				continue
			t2=t1 + abs(b-v2)
			if ret < t2:
				continue
			for k,v3 in enumerate(ll):
				if v3==0:
					continue
				if i==k or j==k:
					continue
				t3 = t2 + abs(c-v3)
				ret=min(ret, t3)
	return ret		
		
def main():
	n , a, b, c = list(map(int, input().split()))
	bb=[]
	for i in range(n):
		bb.append(int(eval(input())))
	ans=a+b+c
	for i in range(4**n-1):
		la=[]
		lb=[]
		lc=[]
		l=[]
		for j in range(n):
			sd=(i%(4 ** (j+1)))//(4**j)
			kk=bb[j]
			pp=0
			if sd == 0:
				la.append(kk)
			elif sd==1:
				lb.append(kk)
			elif sd==2:
				lc.append(kk)
			else:
				l.append(kk)
		pp=max(0,len(la)-1)+max(len(lb)-1,0)+max(0,len(lc)-1)
		l=l+[sum(la),sum(lb),sum(lc)]
		#print(l)
		ans=min(ans,aaa(l,a,b,c)+pp*10)
				
	
	print(ans)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

# Optimized solution
import sys
import queue

#+++++


def aaa(ll,a,b,c):
	ret=a+b+c
	for i,v1 in enumerate(ll):
		if v1==0:
			continue
		t1=abs(a-v1)
		if ret < t1:
			continue
		for j,v2 in enumerate(ll):
			if v2==0:
				continue
			if i==j:
				continue
			t2=t1 + abs(b-v2)
			if ret < t2:
				continue
			for k,v3 in enumerate(ll):
				if v3==0:
					continue
				if i==k or j==k:
					continue
				t3 = t2 + abs(c-v3)
				ret=min(ret, t3)
	return ret		

def mk_str(ll):
	ll.sort()
	return '_'.join([str(v) for v in ll])


def main():
	n , a, b, c = list(map(int, input().split()))
	est=lambda ll:aaa(ll,a,b,c)
	
	bb=[]
	for i in range(n):
		bb.append(int(eval(input())))
	
	cl=set()
	ol=queue.PriorityQueue()
	

	
	st=bb
	ee=est(st)
	cc=0
	cl.add(mk_str(bb))
	ol.put((ee+cc, (cc, bb)))	
	while True:
		if ee == 0:
			return cc
		
		#to goal no join
		rr=cc+ee
		ol.put((rr, (rr, [a,b,c])))
		
		
		
		#join 1
		if len(st) > 3:
			cc+=10
			for i, v in enumerate(st):
				kk=st[:]
				m=kk.pop(i)
				for j, _ in enumerate(kk):
					kkk=kk[:]
					kkk[j]+=m
					stk=mk_str(kkk)
					if stk not in cl:
						cl.add(stk)
						ol.put((cc, (cc, kkk)))
		v,(cc, st) = ol.get()
		ee = est(st)
				
	print(ans)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)
# Original solution
import itertools
n,*abc=list(map(int,input().split()))
l=[int(eval(input())) for i in range(n)]
inf=100000000000000
mi=inf
for i in list(itertools.product([i for i in range(3)],repeat=n)):#(1)↓
    sub=[[] for j in range(3)]
    for j in range(n):
        sub[i[j]].append(j)
    mi_sub=0
    for j in range(3):
        l_sub=len(sub[j])
        if l_sub==0:#(2)
            mi_sub=inf
            break
        mi_subsub=inf
        for k in range(2**l_sub):#(3)↓
            mi_subsubsub=[0,0]
            for l_subsub in range(l_sub):#(5)↓
                if ((k>>l_subsub) &1):
                    mi_subsubsub[0]+=1
                    mi_subsubsub[1]+=l[sub[j][l_subsub]]
            if mi_subsubsub[0]!=0:#(4)
                mi_subsub=min(mi_subsub,abs(mi_subsubsub[1]-abc[j])+mi_subsubsub[0]*10-10)
        mi_sub+=mi_subsub
    mi=min(mi,mi_sub)
print(mi)

# 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):
    '''
    深さがNだったら使用MPを評価
    N本の竹を使うときに必要な合成回数はN-1のため，最後に-1*10*3(?)
    1本も竹を使用していなかったら棄却→MPを無限に使うこととしている
    '''
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF

    '''
    cur番目の竹に対して
        ret0:ABCどれにも使わない
        ret1:Aに使う（合成:MP+10）
        ret2:Bに使う（合成:MP+10）
        ret3:Cに使う（合成:MP+10）
    '''
    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=list(map(int,input().split()))

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

INF=3000

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

    ret0=mp(co+1,a,b,c)
    ret1=mp(co+1,a+l[co],b,c)+10
    ret2=mp(co+1,a,b+l[co],c)+10
    ret3=mp(co+1,a,b,c+l[co])+10

    return min(ret0,ret1,ret2,ret3)

print((mp(0,0,0,0)))


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

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

inf=3000

def mp(g,a,b,c,):
    if g==N:
        return abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a,b,c)>0 else inf

    l0=mp(g+1,a+l[g],b,c)+10
    l1=mp(g+1,a,b+l[g],c)+10
    l2=mp(g+1,a,b,c+l[g])+10
    l3=mp(g+1,a,b,c)
    
    return min(l0,l1,l2,l3)

print((mp(0,0,0,0)))
# Original solution
N,A,B,C=list(map(int,input().split()))
l=[int(eval(input())) for _ in range(N)]
ABC=[A,B,C]

def base2n(Num,n):
    if Num<n:
        return str(Num)
    else:
        return base2n(Num//n,n)+str(Num%n)

ans=10**6
    
for i in range(4**N):
    i_4=("0"*N+base2n(i,4))[-N:]
    Group=[[] for i in range(4)]
    for j in range(N):
        Group[int(i_4[j])-1].append(l[j])
    if len(Group[0])*len(Group[1])*len(Group[2])!=0:
        ans=min(ans,(N-3-len(Group[3]))*10+sum([abs(ABC[j] - sum(Group[j])) for j in range(3)]))
        
print(ans)

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

inf=10**6
    
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
    else:
        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 = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]

ans = 3000
for bits in range(4**n):
    xa = xb = xc = 0
    tmp_ans = 0
    for i in range(n):
        f = (bits//(4**i)) % 4
        if f == 1:
            if xa != 0:
                tmp_ans += 10
            xa += l[i]
        elif f == 2:
            if xb != 0:
                tmp_ans += 10
            xb += l[i]
        elif f == 3:
            if xc != 0:
                tmp_ans += 10
            xc += l[i]

    if xa == 0 or xb == 0 or xc == 0:
        continue
    
    tmp_ans += abs(a - xa) + abs(b - xb) + abs(c - xc)
    ans = min(ans, tmp_ans)

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(index, x, y, z):
    if index == n:
        return abs(a-x) + abs(b-y) + abs(c-z) - 30 if min(x, y, z) > 0 else INF

    cand1 = dfs(index+1, x+l[index], y, z) + 10
    cand2 = dfs(index+1, x, y+l[index], z) + 10
    cand3 = dfs(index+1, x, y, z+l[index]) + 10
    cand4 = dfs(index+1, x, y, z)

    return min(cand1, cand2, cand3, cand4)

print((dfs(0, 0, 0, 0)))
# Original solution
#!/usr/bin/env python
# coding: utf-8

import itertools

def main():
    N, A, B, C = list(map(int, input().split()))
    ll = []
    for _ in range(N):
        ll.append(int(eval(input())))

    cand = []
    ids = set(range(N))
    for a in range(1, N-1):
        for b in range(1, N-a):
            for c in range(1, N-a-b+1):
                cand.append((a, b, c))
    best_cost = -1
    for a, b, c in cand:
        la = itertools.combinations(ids, a)
        for a_ in la:
            lb = itertools.combinations(ids-set(a_), b)
            for b_ in lb:
                lc = itertools.combinations(ids-set(a_)-set(b_), c)
                for c_ in lc:
                    cost = (len(a_)-1)*10 + abs(sum(ll[e] for e in a_)-A)
                    cost += (len(b_)-1)*10 + abs(sum(ll[e] for e in b_)-B)
                    cost += (len(c_)-1)*10 + abs(sum(ll[e] for e in c_)-C)
                    if best_cost == -1 or cost < best_cost:
                        best_cost = cost
    print(best_cost)


if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python
# coding: utf-8

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

def dfs(n, a, b, c):
    if n == N:
        if a == 0 or b == 0 or c == 0: return float('inf')
        return abs(A-a) + abs(B-b) + abs(C-c)
    ca = dfs(n+1, a+ll[n], b, c)
    if a > 0: ca += 10
    cb = dfs(n+1, a, b+ll[n], c)
    if b > 0: cb += 10
    cc = dfs(n+1, a, b, c+ll[n])
    if c > 0: cc += 10
    cn = dfs(n+1, a, b, c)
    return min(ca, cb, cc, cn)


def main():
    print((dfs(0, 0, 0, 0)))


if __name__ == '__main__':
    main()
# Original solution
# XをN進数に変換
def base_number(X:int, N:int):
    res = ""
    while True:
        q, mod = divmod(X,N)
        res += str(mod)
        X = q
        if q == 0:
            break
    return res[::-1]

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

ans = float("inf")
for i in range(4 ** N):
    state = list(base_number(i,4).rjust(N, "0"))
    if not set(["0","1","2"]) <= set(state):
        continue
    
    make = [[] for _ in range(3)]
    for j,x in enumerate(state):
        if x == "3":
            continue
        make[int(x)].append(L[j])
    
    MP = 0
    for j,m in enumerate(make):
        if len(m) == 1:
            MP += abs(B[j] - m[0]) # 延長or短縮魔法
        else:
            MP += (len(m) - 1) * 10 # 合成魔法
            MP += abs(B[j] - sum(m))
    
    ans = min(ans, MP)

print(ans)

# Optimized solution
import sys
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache

N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for i in range(N)]
INF = 10 ** 9

@lru_cache(None)
def dfs(cur, a, b, c):
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) if min(a, b, c) > 0 else INF

    # (10 if _ else 0): 最初の1本目は合成魔法の必要がない
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + (10 if a else 0)
    ret2 = dfs(cur + 1, a, b + l[cur], c) + (10 if b else 0)
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + (10 if c else 0)

    return min(ret0, ret1, ret2, ret3)

print((dfs(0, 0, 0, 0)))
# Original solution
N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
l = list(sorted(l))

tar = []
for x in C, B, A:
    if x in l:
        l.remove(x)
    else:
        tar.append(x)

if not tar:
    print((0))
    exit()

ans = float('inf')
for j in range((len(tar) + 1) ** len(l)):
    vvv = [[] for _ in range(len(tar) + 1)]
    for i in sorted(list(range(len(l))), reverse=True):
        idx, j = divmod(j, (len(tar) + 1) ** i)
        vvv[idx].append(l[i])
    if any(len(vvvv) == 0 for vvvv in vvv[:-1]):
        continue
    else:
        bbb = 0
        # print(tar, vvv)
        for k in range(len(tar)):
            bbb += 10 * (len(vvv[k]) - 1)
            bbb += abs(sum(vvv[k]) - tar[k])
        ans = min(ans, bbb)

print(ans)


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


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
        # A,B,Cに使用する材料を合成し、目的の長さの差を加算（必要なMP）
        # ret1-3で一つ目の材料にも合成魔法のMP10を要求しているので、A,B,Cの初回加算合わせて3回分のMP30を減算
        # a,b,cのいずれかが0のとき、材料が1つも宛がわれていない竹が存在するため、不適（必要MPを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)
    # l[cur]について、使用しないか、(A,B,C)のいずれかに使用の4分岐


print((dfs(0, 0, 0, 0)))
# Original solution
# 4進数

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

ans = INF
for ptn in range(1 << (2 * N)):
    abc = [0 for _ in range(4)]

    v = [None for _ in range(N)]
    # lの各idxをどの竹用に割り当てるか, ABC無 = 0123

    cnt = 0
    for j in range(N):
        v[j] = (ptn >> (2 * j)) & 3
        abc[v[j]] += l[j]
        if 0 <= v[j] < 3:
            cnt += 1

    if 0 in abc[:3]: continue
    ans = min(ans, sum(abs(x - t) for x, t in zip(abc[:3], [A, B, C])) + (cnt - 3) * 10)
print(ans)


# Optimized solution
# dfs

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


def calc(mask):
    abc = [0 for _ in range(4)]
    cnt = 0
    for j in range(N):
        idx = (mask >> (2 * j)) & 3
        abc[idx] += l[j]
        if 0 <= idx < 3:
            cnt += 1
    if 0 in abc[:3]:
        return INF
    return sum(abs(x - t) for x, t in zip(abc, [A, B, C])) + (cnt - 3) * 10


def dfs(cur, mask):
    if cur == N:
        return calc(mask)

    res = INF
    for i in range(4):
        res = min(res, dfs(cur + 1, mask | i << (2 * cur)))
    return res


print((dfs(0, 0)))
# Original solution
inf = float('inf')

n, *goal = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]

ans = inf
for q in range(4 ** n):
    m = [[] for _ in range(4)]
    lm = 0
    for j in range(n):
        idx = (q // (4 ** j)) % 4
        m[idx].append(l[j])
    if any(len(m[idx]) == 0 for idx in range(3)):
        continue

    cost = 0
    for idx in range(3):
        merge_time = len(m[idx]) - 1
        cost += merge_time * 10
        cost += abs(sum(m[idx]) - goal[idx])

    ans = min(ans, cost)

print(ans)


# Optimized solution
inf = float('inf')

n, *goal = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]

ans = inf
for q in range(4 ** n):
    cost = -30
    t = [0] * 3
    for j in range(n):
        idx = (q // (4 ** j)) % 4
        if idx == 3: continue
        t[idx] += l[j]
        cost += 10

    if any(tt == 0 for tt in t):
        continue

    for idx in range(3):
        cost += abs(t[idx] - goal[idx])

    ans = min(ans, cost)

print(ans)