CodeEff/ECCO huggingface dataset:
# Original solution
from itertools import product

def solve(NUM, LIST):
    lst = [l[i] for i, t in enumerate(LIST) if t == NUM]
    if len(lst) == 0:
        return 10 ** 5
    ANS = (len(lst) - 1) * 10
    ANS += abs(sum(lst) - tgt[NUM])
    return ANS

tgt = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(tgt[0])]

ans = 10 ** 5
for pttn in product([0, 1, 2, 3], repeat=tgt[0]):
    tmp = sum(solve(i + 1, pttn) for i in range(3))
    ans = min(ans, tmp)
print(ans)


# Optimized solution
from itertools import product


def solve(T, PTTN):
    lst = [l[i] for i, t in enumerate(PTTN) if t == T]
    if lst:
        ANS = (len(lst) - 1) * 10
        ANS += abs(sum(lst) - tgt[T])
        return ANS
    return 10 ** 5


tgt = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(tgt[0])]

ans = 10 ** 5
for pttn in product([0, 1, 2, 3], repeat=tgt[0]):
    tmp = sum(solve(i + 1, pttn) for i in range(3))
    ans = min(ans, tmp)
print(ans)
# 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)

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

ans=99999
for i in range(4**len(L)):
    i_4_list=list(Base_10_to_n(i, 4).zfill(len(L)))
    at,bt,ct=[],[],[]
    for num,i_4 in enumerate(i_4_list):
        if i_4=='0':
            at.append(L[num])
        elif i_4=='1':
            bt.append(L[num])
        elif i_4=='2':
            ct.append(L[num])
        else:
            continue
    if min(len(at),len(bt),len(ct))>0:
        al=0
        al+=(len(at)+len(bt)+len(ct)-3)*10
        al+=(abs(sum(at)-a)+abs(sum(bt)-b)+abs(sum(ct)-c))
        if al < ans:
            ans=al
print(ans)

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

def dfs(n,a,b,c):
    if n == N:
        if min(a,b,c)>0:
            return abs(A-a)+abs(B-b)+abs(C-c)-30
        else:
            return 10000
    root1=dfs(n+1,a+L[n],b,c)+10
    root2=dfs(n+1,a,b+L[n],c)+10
    root3=dfs(n+1,a,b,c+L[n])+10
    root4=dfs(n+1,a,b,c)
    return min(root1,root2,root3,root4)
    
print((dfs(0,0,0,0)))
# Original solution
import sys
sys.setrecursionlimit(1000000000)
INF=10**9
n,a,b,c=list(map(int,input().split()))
l=[int(eval(input())) for i in range(n)]
def dfs(i,x,y,z,m):
    if i==n:
        if x>0 and y>0 and z>0:
            return abs(x-a)+abs(y-b)+abs(z-c)+m
        else:
            return INF
    ans=INF
    if x==0:
        ans=min(dfs(i+1,l[i],y,z,m),ans)
    else:
        ans=min(dfs(i+1,x+l[i],y,z,m+10),ans)
    if y==0:
        ans=min(dfs(i+1,x,l[i],z,m),ans)
    else:
        ans=min(dfs(i+1,x,y+l[i],z,m+10),ans)
    if z==0:
        ans=min(dfs(i+1,x,y,l[i],m),ans)
    else:
        ans=min(dfs(i+1,x,y,z+l[i],m+10),ans)
    return min(ans,dfs(i+1,x,y,z,m))
print((dfs(0,0,0,0,0)))

# Optimized solution
import sys
sys.setrecursionlimit(1000000000)
INF=10**9
n,a,b,c=list(map(int,input().split()))
l=[int(eval(input())) for i in range(n)]
def dfs(i,x,y,z):
    if i==n:
        if min(x,y,z)>0:
            return abs(x-a)+abs(y-b)+abs(z-c)-30
        else:
            return INF
    ans=dfs(i+1,x,y,z)
    ant=dfs(i+1,x+l[i],y,z)+10
    anu=dfs(i+1,x,y+l[i],z)+10
    anv=dfs(i+1,x,y,z+l[i])+10
    return min(ans,ant,anu,anv)
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 = 10**9
for m in range(4**n):
    length = [0, 0, 0, 0]
    counts = [0, 0, 0, 0]
    for d in range(n-1, -1, -1):
        i = m//(4**d)
        length[i] += l[d]
        counts[i] += 1
        m %= 4**d
        
    if 0 in length[:3]:
        continue
    ans_tmp = 0
    for i in range(3):
        ans_tmp += abs([a,b,c][i] - length[i]) + 10*(counts[i]-1)
    ans = min(ans, ans_tmp)
print(ans)


# Optimized solution
inf = 10**9
n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]

def dfs(i, a_cur, b_cur, c_cur):
    if i == n:
        return abs(a_cur-a) + abs(b_cur-b) + abs(c_cur-c) - 30 if min(a_cur, b_cur, c_cur) > 0 else inf
    ans0 = dfs(i+1, a_cur+l[i], b_cur, c_cur) + 10
    ans1 = dfs(i+1, a_cur, b_cur+l[i], c_cur) + 10
    ans2 = dfs(i+1, a_cur, b_cur, c_cur+l[i]) + 10
    ans3 = dfs(i+1, a_cur, b_cur, c_cur)
    return min(ans0, ans1, ans2, ans3)

print((dfs(0, 0, 0, 0)))
# Original solution
n,a,b,c,*L = list(map(int,open(0).read().split()))
L.sort(reverse = True)

from itertools import product
from copy import deepcopy
li1 = [4,1,2,3]
ans = 10**10
for v in product(li1,repeat = n):
    #print(v)
    num = 0
    A,B,C,NO = [],[],[],[]
    for i in range(n):
        if v[i] == 1:
            #if L[i] not in (a,b,c):
            A.append(L[i])
        elif v[i] == 2:
            #if L[i] not in (a,b,c):
            B.append(L[i])
        elif v[i] == 3:
            #if L[i] not in (a,b,c):
            C.append(L[i])
        elif v[i] == 4:
            NO.append(L[i])
    if A and B and C:
        num +=abs(sum(A)-a) + max(0,(len(A)-1)*10) + abs(sum(B)-b) + max(0,(len(B)-1)*10)+ abs(sum(C)-c) + max(0,(len(C)-1)*10)
        ans = min(ans,num)
    #print(num,ans,A,B,C,max(0,(len(A)-1)*10),max(0,(len(B)-1)*10))
print(ans)

# Optimized solution
from itertools import product

n,a,b,c,*L = list(map(int,open(0).read().split()))

li1 = [1,2,3,4]
ans = 10**10
for v in product(li1,repeat = n):
    num = 0
    A,B,C = [],[],[]
    for i in range(n):
        if v[i] == 1:
            A.append(L[i])
        elif v[i] == 2:
            B.append(L[i])
        elif v[i] == 3:
            C.append(L[i])

    if A and B and C:
        num +=abs(sum(A)-a) + max(0,(len(A)-1)*10) + abs(sum(B)-b) + max(0,(len(B)-1)*10)+ abs(sum(C)-c) + max(0,(len(C)-1)*10)
        ans = min(ans,num)

print(ans)
# Original solution
N, *ABC = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
#print(min(min(func(l, abc)) for abc in [[A,B,C], [A,C,B], [B,A,C], [B,C,A], [C,A,B], [C,B,A]]))

def func(l, ABC, point=0):
    if len(ABC)==0:
        yield point
    else:
        x = ABC[0]
        p = min(abs(x-y) for y in l)
        if x+p in l:
            lc = l.copy()
            lc.remove(x+p)
            yield from func(lc, ABC[1:], point+p)
        if x-p in l:
            lc = l.copy()
            lc.remove(x-p)
            yield from func(lc, ABC[1:], point+p)
from itertools import chain
def func2(l, p, A, B, C):
    # for abc in [[A,B,C], [A,C,B], [B,A,C], [B,C,A], [C,A,B], [C,B,A]]:
    #     print(min(func(l, abc)))
    return min(min(func(l, abc, p)) for abc in [[A,B,C], [A,C,B], [B,A,C], [B,C,A], [C,A,B], [C,B,A]])
def grouping(l, g, h, k):
    if all(len(x)>0 for x in [g, h, k]):
        yield g, h, k
    if len(l)>0:
        a, *l = l
        yield from grouping(l, g+[a], h, k)
        yield from grouping(l, g, h+[a], k)
        yield from grouping(l, g, h, k+[a])
        yield from grouping(l, g, h, k)
def func3(l, ABC):
    for g in grouping(l, [], [], []):
        p = sum(len(gg)-1 for gg in g)*10
        yield func2(list(map(sum, g)), p, *ABC)
print((min(func3(l, ABC))))

# Optimized solution
N, *ABC = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
def grouping(l, g, h, k):
    if all(len(x)>0 for x in [g, h, k]):
        yield g, h, k
    if len(l)>0:
        a, *l = l
        yield from grouping(l, g+[a], h, k)
        yield from grouping(l, g, h+[a], k)
        yield from grouping(l, g, h, k+[a])
        yield from grouping(l, g, h, k)
def func3(l, ABC):
    for g in grouping(l, [], [], []):
        p = sum(len(gg)-1 for gg in g)*10
        l = list(map(sum, g))
        yield sum(abs(x-y) for x,y in zip(l,ABC))+p
print((min(func3(l, ABC))))
# Original solution
import sys
from itertools import product

inf = float('inf')

n, *target = list(map(int, sys.stdin.readline().split()))
target = [None] + target
*l,  = list(map(int, sys.stdin.read().split()))

def main():
    costs = []
    for p in product(list(range(4)), repeat=n):
        tmp = [[] for _ in range(4)]
        p = list(p)
        for i in range(n):
            tmp[p[i]].append(l[i])

        cost = [0] * 4
        for i in range(1, 4):
            if not tmp[i]:
                break
            cost[i] += 10 * (len(tmp[i]) - 1)
            cost[i] += abs(target[i] - sum(tmp[i]))
        else:
            costs.append(sum(cost))

    return min(costs)

if __name__ == '__main__':
    ans = main()
    print(ans)

# Optimized solution
import sys
from itertools import product

n, *abc = list(map(int, sys.stdin.readline().split()))
*l, = list(map(int, sys.stdin.read().split()))

def main():
    cand = []
    for p in product([0, 1, 2, 3], repeat=n):
        group = [[] for _ in range(4)]
        for i in range(n):
            group[p[i]].append(l[i])
        cost = 0
        for i in range(1, 4):
            if not group[i]: 
                break
            cost += 10 * (len(group[i]) - 1)
            group[i] = sum(group[i])
        else:
            group = group[1:]
            for i in range(3):
                cost += abs(abc[i] - group[i])
            cand.append(cost)
        
    print((min(cand)))

if __name__ ==  '__main__':
    main()
# Original solution
import sys
from functools import lru_cache
inf = float('inf')

n, A, B, C, *l = list(map(int, sys.stdin.read().split()))

@lru_cache(None)
def cost(a, b, c, cnt, i):
    if i == n:
        if not (a and b and c): return inf
        return abs(A - a) + abs(B - b) + abs(C - c) + 10 * (cnt - 3)
    return min(cost(a, b, c, cnt, i+1), 
               cost(a+l[i], b, c, cnt+1, i+1),
               cost(a, b+l[i], c, cnt+1, i+1),
               cost(a, b, c+l[i], cnt+1, i+1))

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

if __name__ ==  '__main__':
    main()

# Optimized solution
import sys
inf = float('inf')

n, A, B, C, *l = list(map(int, sys.stdin.read().split()))

def cost(a, b, c, cnt, i):
    if i == n:
        if not (a and b and c): return inf
        return abs(A - a) + abs(B - b) + abs(C - c) + 10 * (cnt - 3)
    return min(cost(a, b, c, cnt, i+1), 
               cost(a+l[i], b, c, cnt+1, i+1),
               cost(a, b+l[i], c, cnt+1, i+1),
               cost(a, b, c+l[i], cnt+1, i+1))

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

if __name__ ==  '__main__':
    main()
# Original solution
import sys

# import bisect
from collections import Counter, deque, defaultdict

# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
import itertools
from operator import attrgetter, itemgetter

# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    ans = INF

    base_idx = list(itertools.permutations(list(range(n)), r=3))

    for bi in base_idx:
        bamboo_length = [0] * 3
        add_bamboo = list(itertools.product(list(range(4)), repeat=(n-3)))
        rem_idx = [i for i in range(n) if i not in bi]
        for ai in add_bamboo:
            mp = 0
            bamboo_length[0] = l[bi[0]]
            bamboo_length[1] = l[bi[1]]
            bamboo_length[2] = l[bi[2]]
            for idx, num in enumerate(ai):
                if num != 3:
                    bamboo_length[num] += l[rem_idx[idx]]
                    mp += 10
            mp += abs(a - bamboo_length[0])
            mp += abs(b - bamboo_length[1])
            mp += abs(c - bamboo_length[2])
            ans = min(mp, ans)

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
import itertools
# from operator import attrgetter, itemgetter
# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    ans = INF

    selects = list(itertools.product(list(range(4)), repeat=n))

    for select in selects:
        mp = -30
        bamboo_length = [0] * 3
        for i, num in enumerate(select):
            if num != 3:
                bamboo_length[num] += l[i]
                mp += 10

        for length in bamboo_length:
            if length == 0:
                break
        else:
            mp += abs(a - bamboo_length[0])
            mp += abs(b - bamboo_length[1])
            mp += abs(c - bamboo_length[2])
            ans = min(mp, ans)

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n, a, b, c = [int(i) for i in input().split()]
L = [int(eval(input())) for i in range(n)]

INF = 10 ** 9

def dfs(i, L, A):
    if all(a == 0 for a in A):
        return 0
    if n - L.count(0) < 3:
        return INF
    if i == n:
        return INF
    if L[i] == 0:
        return dfs(i+1, L[:], A[:])
    for j, a in enumerate(A):
        if a == L[i]:
            A[j] = 0
            return dfs(i+1, L[:], A[:])

    res = dfs(i+1, L[:], A[:])
    for j, a in enumerate(A):
        if a == 0:
            continue
        TL = L[:]
        TL[i] = a
        TA = A[:]
        TA[j] = 0
        d = abs(L[i] - a)
        res = min(res, dfs(i+1, TL, TA) + d)

    if L[i] > max(A):
        return res
    for j in range(i+1, n):
        if L[j] == 0:
            continue
        TL = L[:]
        TL[i] += TL[j]
        TL[j] = 0
        res = min(res, dfs(i, TL, A[:]) + 10)

    return res

print((dfs(0, L[:], [a, b, c])))

# Optimized solution
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

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

INF = 10 ** 9

def dfs(n, a, b, c):
    if n == N:
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else INF
    res = dfs(n+1, a+L[n], b, c) + 10
    res = min(res, dfs(n+1, a, b+L[n], c) + 10)
    res = min(res, dfs(n+1, a, b, c+L[n]) + 10)
    res = min(res, dfs(n+1, a,  b, c))

    return res

print((dfs(0, 0, 0, 0)))
# Original solution
import sys
sys.setrecursionlimit(10**7)

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

ans = []
def f(i, anum, alen, bnum, blen, cnum, clen):
    if i == n:
        if alen * blen * clen == 0:
            return
        mp = abs(anum-a)+10*(alen-1) + abs(bnum-b)+10*(blen-1) + abs(cnum-c)+10*(clen-1)
        ans.append(mp)
    else:
        f(i+1, anum+l[i], alen+1, bnum, blen, cnum, clen)
        f(i+1, anum, alen, bnum+l[i], blen+1, cnum, clen)
        f(i+1, anum, alen, bnum, blen, cnum+l[i], clen+1)
        f(i+1, anum, alen, bnum, blen, cnum, clen)

f(0, 0, 0, 0, 0, 0, 0)

res = float('inf')
for i in ans:
    res = min(res, i)

print(res)

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

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

mp = float('inf')
def f(i, anum, alen, bnum, blen, cnum, clen):
    global mp
    if i == n:
        if alen * blen * clen == 0:
            return
        mp = min(mp, abs(anum-a)+10*(alen-1) + abs(bnum-b)+10*(blen-1) + abs(cnum-c)+10*(clen-1))
    else:
        f(i+1, anum+l[i], alen+1, bnum, blen, cnum, clen)
        f(i+1, anum, alen, bnum+l[i], blen+1, cnum, clen)
        f(i+1, anum, alen, bnum, blen, cnum+l[i], clen+1)
        f(i+1, anum, alen, bnum, blen, cnum, clen)

f(0, 0, 0, 0, 0, 0, 0)


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

from itertools import product
ans = float("inf")
for p in product(list(range(4)),repeat=N):
    a = [L[i] for i in range(N) if p[i]==1]
    b = [L[i] for i in range(N) if p[i]==2]
    c = [L[i] for i in range(N) if p[i]==3]

    if a==[] or b==[] or c==[]:
        continue
    
    t = 0
    for x in [a,b,c]:
        if len(x)>=2:
            t += (len(x)-1)*10
    sumA = sum(a)
    sumB = sum(b)
    sumC = sum(c)
    t += abs(A-sumA) + abs(B-sumB) + abs(C-sumC)

    ans = min(ans,t)

print(ans)

# Optimized solution
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,A,B,C = list(map(int,input().split()))
L = [int(eval(input())) for _ in range(N)]
 
from itertools import product
ans = float("inf")

# 全パターン試す
# 0 : 使わない
# 1,2,3 : A,B,Cとして使う
for p in product(list(range(4)),repeat=N):
    a = [L[i] for i in range(N) if p[i]==1]
    b = [L[i] for i in range(N) if p[i]==2]
    c = [L[i] for i in range(N) if p[i]==3]
 
    if a==[] or b==[] or c==[]:
        continue
    
    t = 0
    for x in [a,b,c]:
        # 複数要素あるなら合成魔法を使って1つに
        if len(x)>=2:
            t += (len(x)-1)*10
    sumA = sum(a)
    sumB = sum(b)
    sumC = sum(c)
    # 目標との差分を 延長魔法or短縮魔法 で埋める
    t += abs(A-sumA) + abs(B-sumB) + abs(C-sumC)
 
    ans = min(ans,t)
 
print(ans)
# Original solution
N,A,B,C = list(map(int,input().split()))
l = [int(eval(input())) for i in range(N)]
INF = 10**9+7

def dfs(count,a,b,c):
	if count == N:
		if min(a,b,c) > 0:
			return abs(a-A)+abs(b-B)+abs(c-C)-30
		else:
			return INF
	non = dfs(count+1,a,b,c)
	useA = dfs(count+1,a+l[count],b,c)+10
	useB = dfs(count+1,a,b+l[count],c)+10
	useC = dfs(count+1,a,b,c+l[count])+10
	return min(non,useA,useB,useC)

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

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

def dfs(cnt,la,lb,lc,cost):
    if cnt == N:
        if la == 0 or lb == 0 or lc == 0:
            return 10**10
        else:
            return cost+abs(A-la)+abs(B-lb)+abs(C-lc)-30
    else:
        a = dfs(cnt+1,la+L[cnt],lb,lc,cost+10)
        b = dfs(cnt+1,la,lb+L[cnt],lc,cost+10)
        c = dfs(cnt+1,la,lb,lc+L[cnt],cost+10)
        d = dfs(cnt+1,la,lb,lc,cost) 
        return min(a,b,c,d)

print((dfs(0,0,0,0,0)))
# Original solution
n,a,b,c = list(map(int,input().split()))
l = [int(eval(input())) for i in range(n)]
def dfs(cnt,A,B,C):
    if cnt == n:
        if min(A,B,C) == 0:
            return float('inf')
        else:
            return abs(a-A)+abs(b-B)+abs(c-C)-30
    else:
        ret1 = dfs(cnt+1,A+l[cnt],B,C)+10
        ret2 = dfs(cnt+1,A,B+l[cnt],C)+10
        ret3 = dfs(cnt+1,A,B,C+l[cnt])+10
        ret4 = dfs(cnt+1,A,B,C)
        return min(ret1,ret2,ret3,ret4)
print((dfs(0,0,0,0)))

# Optimized solution
N,A,B,C = list(map(int,input().split()))
L = [int(eval(input())) for i in range(N)]
def dfs(i,la,lb,lc,cost):
    if i == N:
        if la*lb*lc == 0:
            return 10**20
        else:
            return abs(A-la)+abs(B-lb)+abs(C-lc)-30+cost
    ret1 = dfs(i+1,la+L[i],lb,lc,cost+10)
    ret2 = dfs(i+1,la,lb+L[i],lc,cost+10)
    ret3 = dfs(i+1,la,lb,lc+L[i],cost+10)
    ret4 = dfs(i+1,la,lb,lc,cost)
    return min(ret1,ret2,ret3,ret4)
print((dfs(0,0,0,0,0)))
# Original solution
N = 0
N, A, B, C = [int(s) for s in input().split()]

bamboos = [int(eval(input())) for _ in range(N)]


def divide(l):
    if len(l) == 0:
        return []
    if len(l) == 1:
        return [
            [[], [], []],  # 使わない
            [[l[0]], [], []],  # A で使う
            [[], [l[0]], []],  # B で使う
            [[], [], [l[0]]],  # C で使う
        ]

    res = []
    for a, b, c in divide(l[1:]):
        # 使わない
        res.append([a, b, c])
        # A で使う
        res.append([l[0:1] + a, b, c])
        # B で使う
        res.append([a, l[0:1] + b, c])
        # C で使う
        res.append([a, b, l[0:1] + c])

    return res


min_mp = -1
for a, b, c in divide(bamboos):
    al, ac = sum(a), len(a)
    bl, bc = sum(b), len(b)
    cl, cc = sum(c), len(c)
    if al == 0 or bl == 0 or cl == 0:
        continue

    # 合成に使った魔力
    composite = 10 * ((ac - 1) + (bc - 1) + (cc - 1))
    # 総合魔力
    mp = abs(al - A) + abs(bl - B) + abs(cl - C) + composite

    if mp < min_mp or min_mp == -1:
        min_mp = mp

print(min_mp)


# Optimized solution
N = 0
N, A, B, C = [int(s) for s in input().split()]

bamboos = [int(eval(input())) for _ in range(N)]


# def divide(l):
#     if len(l) == 0:
#         return []
#     if len(l) == 1:
#         return [
#             [[], [], []],  # 使わない
#             [[l[0]], [], []],  # A で使う
#             [[], [l[0]], []],  # B で使う
#             [[], [], [l[0]]],  # C で使う
#         ]

#     res = []
#     for a, b, c in divide(l[1:]):
#         # 使わない
#         res.append([a, b, c])
#         # A で使う
#         res.append([l[0:1] + a, b, c])
#         # B で使う
#         res.append([a, l[0:1] + b, c])
#         # C で使う
#         res.append([a, b, l[0:1] + c])

#     return res


# min_mp = -1
# for a, b, c in divide(bamboos):
#     al, ac = sum(a), len(a)
#     bl, bc = sum(b), len(b)
#     cl, cc = sum(c), len(c)
#     if al == 0 or bl == 0 or cl == 0:
#         continue

#     # 合成に使った魔力
#     composite = 10 * ((ac - 1) + (bc - 1) + (cc - 1))
#     # 総合魔力
#     mp = abs(al - A) + abs(bl - B) + abs(cl - C) + composite

#     if mp < min_mp or min_mp == -1:
#         min_mp = mp

# print(min_mp)

# ------------------------
# dfs を使うともっと短くかける
# ------------------------
def dfs(l, a, b, c):
    global A, B, C
    INF = 10**18
    if len(l) == 0:
        if min(a, b, c) > 0:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
        else:
            return INF

    ret0 = dfs(l[1:], a, b, c)  # l[0] を使わない
    retA = dfs(l[1:], a + l[0], b, c) + 10  # l[0] を A で使う
    retB = dfs(l[1:], a, b + l[0], c) + 10  # l[0] を B で使う
    retC = dfs(l[1:], a, b, c + l[0]) + 10  # l[0] を C で使う

    return min(ret0, retA, retB, retC)


print((dfs(bamboos, 0, 0, 0)))
# Original solution
ri = lambda: int(eval(input()))
rl = lambda: list(map(int,input().split()))

N,A,B,C=rl()
l=[0]*N
for i in range(N):
    l[i] = ri()
ans = float('inf')
for n in range(4**N):
    a,b,c=0,0,0
    ans_ = 0
    for i in range(N):
        sn = format(n>>(2*i),'0{}b'.format(N))[-2:]
        if sn=='01':
            a+=l[i]
            ans_ += 10
        elif sn=='10':
            b+=l[i]
            ans_ += 10
        elif sn=='11':
            c+=l[i]
            ans_ += 10
    if a!=0 and b!=0 and c!=0:
        ans_ += abs(A-a)+abs(B-b)+abs(C-c) -30
        if ans > ans_:
            ans = ans_

print(ans)

# Optimized solution
ri = lambda: int(eval(input()))
rl = lambda: list(map(int,input().split()))

N,A,B,C=rl()
l=[ri() for _ in range(N)]
ans = 10**18
import itertools
for seq in itertools.product(list(range(4)),repeat=N):
    a,b,c=0,0,0
    rst = 0
    for i in range(N):
        if seq[i]==1:
            a+=l[i]
            rst+=10
        elif seq[i]==2:
            b+=l[i]
            rst+=10
        elif seq[i]==3:
            c+=l[i]
            rst+=10
    if a*b*c != 0:
        rst += abs(A-a)+abs(B-b)+abs(C-c)-30
        if ans > rst:
            ans = rst

print(ans)