CodeEff/ECCO huggingface dataset:
# 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):
    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)


# Optimized solution
inf = float('inf')


def calc(mask):
    cost = -30
    t = [0] * 3
    for j in range(n):
        idx = (mask >> (2 * j)) & 3
        if idx == 3: continue
        t[idx] += l[j]
        cost += 10

    if 0 in t[:3]:
        return inf

    cost += sum(abs(tt - gg) for tt, gg in zip(t, goal))
    return cost


def dfs(cur, mask):
    # l[cur]をa,b,c,未使用のいずれかにあてがう

    # base case
    if cur == n:
        return calc(mask)

    res = inf
    for i in range(4):
        # i == 0,1,2 : a,b,cにあてがう / i == 3 : 未使用
        res = min(res, dfs(cur + 1, mask | i << (2 * cur)))
    return res


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

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


def calc(mask):
    cost = -30
    t = [0] * 3
    for j in range(n):
        idx = (mask >> (2 * j)) & 3
        if idx == 3: continue
        t[idx] += l[j]
        cost += 10

    if 0 in t[:3]:
        return inf

    cost += sum(abs(tt - gg) for tt, gg in zip(t, goal))
    return cost


def dfs(cur, mask):
    # l[cur]をa,b,c,未使用のいずれかにあてがう

    # base case
    if cur == n:
        return calc(mask)

    res = inf
    for i in range(4):
        # i == 0,1,2 : a,b,cにあてがう / i == 3 : 未使用
        res = min(res, dfs(cur + 1, mask | i << (2 * cur)))
    return res


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

print((dfs(0, 0)))


# Optimized solution
inf = float('inf')


def calc(mask):
    t = [0] * 3
    cnt = 0
    for j in range(n):
        idx = (mask >> (2 * j)) & 3
        if idx == 3:
            cnt += 1
            continue
        t[idx] += l[j]

    if 0 in t:
        return inf

    return sum(abs(tt - gg) for tt, gg in zip(t, goal)) + (n - cnt - 3) * 10


def dfs(cur, mask):
    # l[cur]をa,b,c,未使用のいずれかにあてがう

    # base case
    if cur == n:
        return calc(mask)

    res = inf
    for i in range(4):
        # i == 0,1,2 : a,b,cにあてがう / i == 3 : 未使用
        res = min(res, dfs(cur + 1, mask | i << (2 * cur)))
    return res


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

print((dfs(0, 0)))
# Original solution
l=[]
n,a,b,c=list(map(int,input().split()))
for i in range(n):
    li=int(eval(input()))
    l.append(li)

d=[a,b,c]
d.sort()

mpmin=sum(l)*4+len(l)*10+sum(d)
for i in range(4**n):
    k=[]
    kj=i%4
    k.append(kj)
    b=int((i-kj)/4)
    l0=[]
    l1=[]
    l2=[]
    l3=[]
    if kj==0:
        l0.append(l[0])
    elif kj==1:
        l1.append(l[0])
    elif kj==2:
        l2.append(l[0])
    elif kj==3:
        l3.append(l[0])
        
    for j in range(n-1):
        kj=b%4
        k.append(kj)
        b=int((b-kj)/4)
        if kj==0:
            l0.append(l[j+1])
        elif kj==1:
            l1.append(l[j+1])
        elif kj==2:
            l2.append(l[j+1])
        elif kj==3:
            l3.append(l[j+1])
    mp=0
    if len(l0)>=1:
        mp=mp+(len(l0)-1)*10
    if len(l1)>=1:
        mp=mp+(len(l1)-1)*10
    if len(l2)>=1:
        mp=mp+(len(l2)-1)*10
    ls=[]
    ls=[sum(l0),sum(l1),sum(l2)]
    ls.sort()
    mp=mp+abs(d[0]-ls[0])+abs(d[1]-ls[1])+abs(d[2]-ls[2])    
    if mpmin>mp and len(l0)>=1 and len(l1)>=1 and len(l2)>=1:
        mpmin=mp
print(mpmin)        
        


# Optimized solution

n,a,b,c=list(map(int,input().split()))
l=[0]*n
for i in range(n):
    l[i]=int(eval(input()))
    
import itertools
 
mpmin=a+b+c+1
for i in itertools.product([0,1,2,3], repeat=n):
    aa=0
    bb=0
    cc=0
    mpa=0
    mpb=0
    mpc=0
    ia=0
    ib=0
    ic=0
    for ii in range(n):
        if i[ii]==1:
            ia=1
            if aa>0:
                mpa+=10
            aa+=l[ii]
        elif i[ii]==2:
            ib=1
            if bb>0:
                mpb+=10
            bb+=l[ii]
        elif i[ii]==3:
            ic=1
            if cc>0:
                mpc+=10
            cc+=l[ii]
    if ia==1 and ib==1 and ic==1:
        mp=mpa+abs(a-aa)+mpb+abs(b-bb)+mpc+abs(c-cc)
#        if mp<mpmin:
#            print(mp,mpa,mpb,mpc,i)
        mpmin=min(mp,mpmin)

print(mpmin)
# Original solution

n,a,b,c=list(map(int,input().split()))
l=[0]*n
for i in range(n):
    l[i]=int(eval(input()))
    
import itertools
 
mpmin=a+b+c+1
for i in itertools.product([0,1,2,3], repeat=n):
    aa=0
    bb=0
    cc=0
    mpa=0
    mpb=0
    mpc=0
    ia=0
    ib=0
    ic=0
    for ii in range(n):
        if i[ii]==1:
            ia=1
            if aa>0:
                mpa+=10
            aa+=l[ii]
        elif i[ii]==2:
            ib=1
            if bb>0:
                mpb+=10
            bb+=l[ii]
        elif i[ii]==3:
            ic=1
            if cc>0:
                mpc+=10
            cc+=l[ii]
    if ia==1 and ib==1 and ic==1:
        mp=mpa+abs(a-aa)+mpb+abs(b-bb)+mpc+abs(c-cc)
#        if mp<mpmin:
#            print(mp,mpa,mpb,mpc,i)
        mpmin=min(mp,mpmin)

print(mpmin)    


# Optimized solution

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

inf=10**9

def dfs(cur,aa,bb,cc):
    if cur==n:
        if min(aa,bb,cc)>0:
            return abs(a-aa)+abs(b-bb)+abs(c-cc)-30
        else:
            return inf
    ret0=dfs(cur+1,aa,bb,cc)
    ret1=dfs(cur+1,aa+l[cur],bb,cc)+10
    ret2=dfs(cur+1,aa,bb+l[cur],cc)+10
    ret3=dfs(cur+1,aa,bb,cc+l[cur])+10
#    print(cur,l[cur],aa,bb,cc,ret0,ret1,ret2,ret3)
    return min(ret0,ret1,ret2,ret3)

print((dfs(0,0,0,0)))
# Original solution
# coding: utf-8
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
    
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
ans = float("inf")
for i in range(4**N):
    bits = Base_10_to_n(i, 4).zfill(N)
    a, b, c = 0, 0, 0
    cost = 0
    for j in range(len(bits)):
        if bits[j] == "0":
            pass
        elif bits[j] == "1":
            a += L[j]
            cost += 10
        elif bits[j] == "2":
            b += L[j]
            cost += 10
        else:
            c += L[j]
            cost += 10
    if min(a, b, c) > 0:
        ans = min(ans, cost + abs(a-A)+abs(b-B)+abs(c-C) - 10*3)
print(ans)

# Optimized solution
# coding: utf-8
import sys
sys.setrecursionlimit(10**9)
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
N, A, B, C = list(map(int, input().split()))
L = []
for i in range(N):
    L.append(int(eval(input())))
# L.sort()
def dfs(cnt, a, b, c):
    if cnt == N:
        return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a,b,c) > 0 else 10**9
    r0 = dfs(cnt+1, a, b, c)
    r1 = dfs(cnt+1, a+L[cnt], b, c) + 10
    r2 = dfs(cnt+1, a, b+L[cnt], c) + 10
    r3 = dfs(cnt+1, a, b, c+L[cnt]) + 10
    return min(r0, r1, r2, r3)
    
print((dfs(0,0,0,0)))
# Original solution
# coding: utf-8
import sys
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# N本の竹それぞれA, B, C, 使わないか
N, A, B, C = lr()
bamboo = [ir() for _ in range(N)]
answer = 10 **  5
for pattern in itertools.product(list(range(4)), repeat=N):
    mp = 0
    Alist = []; Blist = []; Clist = []
    for i, p in enumerate(pattern):
        if p == 0:
            Alist.append(bamboo[i])
        elif p == 1:
            Blist.append(bamboo[i])
        elif p == 2:
            Clist.append(bamboo[i])
    if len(Alist) == 0 or len(Blist) == 0 or len(Clist) == 0:
        continue
    mp += 10 * (len(Alist) + len(Blist) + len(Clist) - 3)
    mp += abs(A - sum(Alist)) + abs(B - sum(Blist)) + abs(C - sum(Clist))
    if mp < answer:
        answer = mp

print(answer)
# 04

# Optimized solution
# coding: utf-8
import sys
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# Nは最大8まで、Aに使う竹はどれ？
N, A, B, C = lr()
bamboo = [ir() for _ in range(N)]
answer = 10 ** 5
for pattern in itertools.product(list(range(4)), repeat=N):
    use = [0] * 3
    mp = 0
    for p, bam in zip(pattern, bamboo):
        if p == 3:
            continue
        if use[p] != 0:
            mp += 10
        use[p] += bam
    if use.count(0) != 0:
        continue
    mp += abs(A-use[0]) + abs(B-use[1]) + abs(C-use[2])
    if mp < answer:
        answer = mp

print(answer)
# 23
# Original solution
from itertools import product, permutations

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

ans = 10 ** 9
for groups in product(list(range(4)), repeat=N):
    items = []
    group_a = []
    group_b = []
    group_c = []

    for group, length in zip(groups, L):
        if group == 0:
            items.append((length, 0))
        elif group == 1:
            group_a.append(length)
        elif group == 2:
            group_b.append(length)
        elif group == 3:
            group_c.append(length)

    if group_a:
        items.append((sum(group_a), (len(group_a) - 1) * 10))
    if group_b:
        items.append((sum(group_b), (len(group_b) - 1) * 10))
    if group_c:
        items.append((sum(group_c), (len(group_c) - 1) * 10))

    if len(items) < 3:
        continue

    for one, two, three in permutations((A, B, C), r=3):
        cost = 0
        _items = list(items)

        _items = sorted(_items, key=lambda x: (abs(x[0] - one), x[1]))
        cost += abs(_items[0][0] - one) + _items[0][1]
        _items.pop(0)

        _items = sorted(_items, key=lambda x: (abs(x[0] - two), x[1]))
        cost += abs(_items[0][0] - two) + _items[0][1]
        _items.pop(0)

        _items = sorted(_items, key=lambda x: (abs(x[0] - three), x[1]))
        cost += abs(_items[0][0] - three) + _items[0][1]

        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 ** 9
for groups in product(list(range(4)), repeat=N):
    length_a = 0
    length_b = 0
    length_c = 0
    cost_a = -10
    cost_b = -10
    cost_c = -10

    for group, length in zip(groups, L):
        if group == 1:
            length_a += length
            cost_a += 10
        elif group == 2:
            length_b += length
            cost_b += 10
        elif group == 3:
            length_c += length
            cost_c += 10

    if 0 in {length_a, length_b, length_c}:
        continue

    ans = min(ans, sum([
        abs(A - length_a),
        abs(B - length_b),
        abs(C - length_c),
        cost_a,
        cost_b,
        cost_c,
    ]))

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

min_cost = 10 ** 18

def func(n, select):
	global min_cost
	if n == 0:
		if len(set(select) - {0}) < 3:
			return
		#print(select)
		cost = 0
		a, b, c = 0, 0, 0
		for i, t in enumerate(select):
			if t == 1:
				if a != 0:
					cost += 10
				a += L[i]
			if t == 2:
				if b != 0:
					cost += 10
				b += L[i]
			if t == 3:
				if c != 0:
					cost += 10
				c += L[i]
		cost += abs(A - a)
		cost += abs(B - b)
		cost += abs(C - c)
		min_cost = min(min_cost, cost)
		return
	for i in range(4):
		func(n - 1, select + [i])

func(N, [])
print(min_cost)


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

INF = 10 ** 12

def solve(n, cost, a, b, c):
	if n == N:
		if 0 == min(a, b, c):
			return INF
		return abs(a - A) + abs(b - B) + abs(c - C) + cost - 30
	ret1 = solve(n + 1, cost, a, b, c)
	ret2 = solve(n + 1, cost + 10, a + L[n], b, c)
	ret3 = solve(n + 1, cost + 10, a, b + L[n], c)
	ret4 = solve(n + 1, cost + 10, a, b, c + L[n])
	return min(ret1, ret2, ret3, ret4)

print((solve(0, 0, 0, 0, 0)))
# Original solution
n,a,b,c = list(map(int,input().split()))
takelist = [a,b,c]

li = [int(eval(input())) for _ in range(n)]
li2 = [0 for _ in range(n)]
min = 10**100

def movelist(li,n):
    for i in range(n):
        if li[i] != 3:
            li[i] += 1
            break
        else:
            li[i] = 0

for i in range(4**n):
    li3 = [0,0,0,0]
    sum = 0
    for j in range(n):
        if li3[li2[j]] != 0 and li2[j] != 3:
            sum += 10
        li3[li2[j]] += li[j]
    if li3[0] != 0 and li3[1] != 0 and li3[2] != 0:
        for k in range(3):
            sum += abs(li3[k] - takelist[k])
        if sum < min:
            min = sum
    movelist(li2,n)

print(min)


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

def searchans(count,a,b,c):
    if count == n:
        if not 0 in [a,b,c]:
            return abs(A-a) + abs(B-b) + abs(C-c) - 30
        else:
            return 10**100
    else:
        ret0 = searchans(count+1,a,b,c)
        ret1 = searchans(count+1,a+li[count],b,c) + 10
        ret2 = searchans(count+1,a,b+li[count],c) + 10
        ret3 = searchans(count+1,a,b,c+li[count]) + 10
        return min([ret0,ret1,ret2,ret3])

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


n_bamboo, b1, b2, b3 = [int(i) for i in input().split()]
bamboos = [int(eval(input())) for _ in range(n_bamboo)]

ans = float("inf")
# すべての竹について、b1, b2, b3のどの竹に使うかを列挙
# 0のときはどの竹にも使わない
for bit in itertools.product((0, 1, 2, 3), repeat=n_bamboo):
    l1, l2, l3 = 0, 0, 0
    c1, c2, c3 = 0, 0, 0
    # 選択した竹を足す（2つ目以降はMP10消費）
    for b, bamboo in zip(bit, bamboos):
        if b == 1:
            if l1 > 0:
                c1 += 10
            l1 += bamboo
        elif b == 2:
            if l2 > 0:
                c2 += 10
            l2 += bamboo
        elif b == 3:
            if l3 > 0:
                c3 += 10
            l3 += bamboo
    # 1つも構成する竹がない竹がある場合はスキップ
    if l1 * l2 * l3 == 0:
        continue
    # 延長、短縮のコスト
    c1 += abs(b1 - l1)
    c2 += abs(b2 - l2)
    c3 += abs(b3 - l3)
    # 合計コストが今までより低ければ更新
    ans = min(ans, c1 + c2 + c3)
print(ans)


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


N, A, B, C = [int(i) for i in input().split()]
l = [int(eval(input())) for _ in range(N)]
print((dfs(0, 0, 0, 0)))
# Original solution
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def choose3(bamboos: list, a: int, b: int, c: int):
    bamboos.sort(reverse=True)
    l = len(bamboos)
    minmp = float('inf')
    
    for idx in range(l):
        for jdx in range(idx+1,l):
            for kdx in range(jdx+1,l):
                minmp = min(minmp,
                            abs(bamboos[idx]-a)\
                             + abs(bamboos[jdx]-b)\
                             + abs(bamboos[kdx]-c))
    return minmp


def dfs(bamboos: list, a: int, b: int, c: int, mp: int):

    l = len(bamboos)
    
    if l == 3:
        return mp + choose3(bamboos, a, b, c)
    
    else:
        minmp = mp + choose3(bamboos, a, b, c)
        
        for p1 in range(l):
            for p2 in range(p1+1,l):
                newbamboos = [bamboos[p1] + bamboos[p2]]
                
                for p in range(l):
                    if p == p1 or p == p2:
                        continue
                    else:
                        newbamboos.append(bamboos[p])
                
                minmp = min(minmp, dfs(newbamboos, a, b, c, mp+10))
                del newbamboos
                
        return minmp
    
n,a,b,c = li()
laaa = [ni() for _ in range(n)]

print((dfs(laaa, a, b, c, 0)))

# Optimized solution
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**2) 
 
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,a,b,c = li()
l = [ni() for _ in range(n)]

ans = 10**18

for i in range(4**n):
    cur = i
    cnt = {i: [] for i in range(4)}
    
    for bi in l:
        cnt[cur%4].append(bi)
        cur //= 4
    
    
    if len(cnt[1]) * len(cnt[2]) * len(cnt[3]) == 0:
        continue
    
    ans = min(ans, abs(a-sum(cnt[1]))\
                  + abs(b-sum(cnt[2]))\
                  + abs(c-sum(cnt[3]))\
                  + 10*(n - len(cnt[0]) -3))
    
print(ans)
# Original solution
import itertools

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

for i in range(N):
    l.append(int(eval(input())))
    
prod = list(itertools.product(['A','B','C','X'], repeat=N))

mps = []

for prod_e in prod:
    if prod_e.count('A') * prod_e.count('B') * prod_e.count('C') != 0:
        mp = 0
        length = {'A':0, 'B':0, 'C':0, 'X':0}
        for index, prod_e_e in enumerate(prod_e):
            length[prod_e_e] += l[index]
        mp += abs(length['A'] - A) + abs(length['B'] - B) + abs(length['C'] - C)
        mp += (prod_e.count('A')-1) * 10 + (prod_e.count('B')-1) * 10 + (prod_e.count('C')-1) * 10
        mps.append(mp)

print((min(mps)))

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

for i in range(N):
    l.append(int(eval(input())))
    
def dfs(syn, n, a, b, c):
    if n == N:
        if a*b*c != 0:
            mp = abs(A-a) + abs(B-b) + abs(C-c)
            mp += syn * 10 - 30
            return mp
        else:
            return 10**9
    else:
        branch1 = dfs(syn+1, n+1, a + l[n], b, c)
        branch2 = dfs(syn+1, n+1, a, b + l[n], c)
        branch3 = dfs(syn+1, n+1, a, b, c + l[n])
        branch4 = dfs(syn, n+1, a, b, c)
        return min(branch1, branch2, branch3, branch4)
        
print((dfs(0, 0, 0, 0, 0)))
# Original solution
#https://atcoder.jp/contests/abc119/tasks/abc119_c
#2019-02-24
N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]


ans = float("inf")
# 00 なら使わない、 01 ならAをつくる、10 ならBをつくる、11ならCをつくる　
for i in range(1 << 2*N):
    cost = float("inf")
    A_hon = 0
    B_hon = 0
    C_hon = 0
    A_zai = 0
    B_zai = 0
    C_zai = 0
    for k in range(N):
        if i & (1<<(2*k)) and i & (1<< (2*k)+1):
            C_hon += 1
            C_zai += l[k]
        elif i & (1<<(2*k)+1):
            B_hon += 1
            B_zai += l[k]
        elif i & (1<<(2*k)):
            A_hon += 1
            A_zai += l[k]
    if A_hon * B_hon * C_hon >0:
       cost = 10*(A_hon - 1)+ abs(A_zai - A)+10*(B_hon - 1)+ abs(B_zai - B)+ 10*(C_hon - 1)+ abs(C_zai - C)
    ans = min(cost, ans)
print(ans)

# Optimized solution
#https://atcoder.jp/contests/abc119/tasks/abc119_c
#2019-02-24
N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]


ans = []
# 00 なら使わない、 01 ならAをつくる、10 ならBをつくる、11ならCをつくる　
for i in range(1 << 2*N):
    A_hon = 0
    B_hon = 0
    C_hon = 0
    A_zai = 0
    B_zai = 0
    C_zai = 0
    for k in range(N):
        if i & (1<<(2*k)) and i & (1<< (2*k)+1):
            C_hon += 1
            C_zai += l[k]
        elif i & (1<<(2*k)+1):
            B_hon += 1
            B_zai += l[k]
        elif i & (1<<(2*k)):
            A_hon += 1
            A_zai += l[k]
    if A_hon * B_hon * C_hon >0:
       ans += [10*(A_hon - 1)+ abs(A_zai - A)+10*(B_hon - 1)+ abs(B_zai - B)+ 10*(C_hon - 1)+ abs(C_zai - C)]
print((min(ans)))
# Original solution
#https://atcoder.jp/contests/abc119/tasks/abc119_c
#2019-02-24
N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]


ans = []
# 00 なら使わない、 01 ならAをつくる、10 ならBをつくる、11ならCをつくる　
for i in range(1 << 2*N):
    A_hon = 0
    B_hon = 0
    C_hon = 0
    A_zai = 0
    B_zai = 0
    C_zai = 0
    for k in range(N):
        if i & (1<<(2*k)) and i & (1<< (2*k)+1):
            C_hon += 1
            C_zai += l[k]
        elif i & (1<<(2*k)+1):
            B_hon += 1
            B_zai += l[k]
        elif i & (1<<(2*k)):
            A_hon += 1
            A_zai += l[k]
    if A_hon * B_hon * C_hon >0:
       ans += [10*(A_hon - 1)+ abs(A_zai - A)+10*(B_hon - 1)+ abs(B_zai - B)+ 10*(C_hon - 1)+ abs(C_zai - C)]
print((min(ans)))

# Optimized solution
import itertools
N, *A = list(map(int,input().split()))
l = [int(eval(input())) for i in range(N)]
li =  itertools.product(list(range(4)), repeat=N)

ans = float("inf")
for i in li:
  cnt = [0]*3
  length = [0]*3
  for k in range(N):
    if i[k] == 3: 
      continue
    cnt[i[k]] += 1
    length[i[k]] += l[k]
  if min(cnt) > 0:
    cost = sum([abs(length[i]-A[i]) +10*cnt[i] for i in range(3)]) -30
    ans = min(ans, cost)
  
print(ans)
# Original solution
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]

import itertools
m = 4
n = N
bit_list = list(itertools.product([i for i in range(m)], repeat=n))

res = 10 ** 18
for b in bit_list:
    tmp1 = 0
    tmp2 = 0
    tmp3 = 0
    check1 = False
    check2 = False
    check3 = False
    cost = 0
    for i in range(n):
        if b[i] == 1:
            tmp1 += L[i]
            if check1:
                cost += 10
            check1 = True       
            
        if b[i] == 2:
            tmp2 += L[i]
            if check2:
                cost += 10
            check2 = True
            
        if b[i] == 3:
            tmp3 += L[i]
            if check3:
                cost += 10
            check3 = True
    if min(tmp1, tmp2, tmp3) != 0:
        res = min(res, abs(tmp1 - A)+abs(tmp2 - B)+abs(tmp3 - C)+cost)
print(res)

# Optimized solution
N, A, B, C = list(map(int, input().split()))
L = []
for i in range(N):
    L.append(int(eval(input())))
    
import itertools
m = 4
bit_list = list(itertools.product([i for i in range(m)], repeat=N))
ans = 10 ** 18
for bit in bit_list:
    retA = 0
    retB = 0
    retC = 0
    checkA = False
    checkB = False
    checkC = False
    cost = 0
    for i,j in enumerate(bit):
        if j == 1:
            retA += L[i]
            if checkA:
                cost += 10
            checkA = True
        if j == 2:
            retB += L[i]
            if checkB:
                cost += 10
            checkB = True
        if j == 3:
            retC += L[i]
            if checkC:
                cost += 10
            checkC = True
    if min(retA,retB,retC) != 0:
        ans = min(ans, abs(A-retA)+abs(B-retB)+abs(C-retC)+cost)
print(ans)