You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:
 - Extension Magic: Consumes 1 MP (magic point). Choose one bamboo and increase its length by 1.
 - Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
 - Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective?

-----Constraints-----
 - 3 \leq N \leq 8
 - 1 \leq C < B < A \leq 1000
 - 1 \leq l_i \leq 1000
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N

-----Output-----
Print the minimum amount of MP needed to achieve the objective.

-----Sample Input-----
5 100 90 80
98
40
30
21
80

-----Sample Output-----
23

We are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98, 40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain bamboos of lengths 100, 90 by using the magics as follows at the total cost of 23 MP, which is optimal.
 - Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)
 - Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)
 - Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)
 - Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)

Difficulty: introductory

Starter code:

Solutions:
N,A,B,C = map(int,input().split())
l = [int(input()) for _ in range(N)]
ans = float("inf")
for i in range(4**N):
    a,b,c = [],[],[]
    cost = 0
    for j in range(N):
        r = (i//(4**j)) % 4
        if r == 1:
            a.append(l[j])
        elif r == 2:
            b.append(l[j])
        elif r == 3:
            c.append(l[j])
    if a and b and c:
        cost += sum(max((len(x)-1), 0)*10 for x in [a,b,c])
        a = sum(a)
        b = sum(b)
        c = sum(c)
        cost += sum(abs(x-y) for x,y in [(a,A),(b,B),(c,C)])
        ans = min(ans, cost)
print(ans)

from itertools import product

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

minscore=10**9
for p in product(range(-1,3),repeat=N):
  flag=0
  score = 0
  n_abc=[0,0,0]
  sumlen = [0,0,0]
  for i in range(N):
    if p[i] != -1:
      n_abc[p[i]] += 1
      sumlen[p[i]] += l[i]
  for j in range(3):
    if n_abc[j] == 0:
      flag=1
      break
    score += (n_abc[j]-1)*10 + abs(sumlen[j]-[A,B,C][j])
    
  if flag:
    continue
    
  if score < minscore:
    minscore = score
    
print(minscore)

n,a,b,c = map(int, input().split())

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

import itertools

bumboo=["A","B","C","D"]

prod = list(itertools.product(bumboo,repeat=n))

temp = []

for i in prod:
    tempa = 0
    tempb = 0
    tempc = 0
    for j in range(n):
        if i[j] =="A":
            tempa += l[j]
        elif i[j] =="B":
            tempb += l[j]
        elif i[j] =="C":
            tempc += l[j]
    if tempa*tempb*tempc == 0:
        pass
    else:
        temp.append(abs(tempa-a)+abs(tempb-b)+abs(tempc-c)+10*(n-3-i.count("D")))
print(min(temp))

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

INF = 10 ** 9

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

    ret1 = dfs(a, b, c, n + 1)
    ret2 = dfs(a + L_list[n], b, c, n + 1) + 10
    ret3 = dfs(a, b + L_list[n], c, n + 1) + 10
    ret4 = dfs(a, b, c + L_list[n], n + 1) + 10
    return min(ret1, ret2, ret3, ret4)


ans = dfs(0, 0, 0, 0)
print(ans)
'''
8 100 90 80
100
100
90
90
90
80
80
80

0


8 1000 800 100
300
333
400
444
500
555
600
666

243

'''

def main():
    n, *target = list(map(int, input().split()))
    l = [int(input()) for _ in range(n)]
    ans = float("inf")
    base = 4
    for i in range(pow(base, n)):
        now_l = [0] * base
        add = [0] * base
        now = i
        for j in range(n):
            now_l[now % base] += l[j]
            add[now % base] += 1
            now //= base
        if 0 in now_l[:base - 1]:
            continue
        now_ans = sum([abs(target[i] - now_l[i]) for i in range(3)]) + (sum(add[:3]) - 3) * 10
        ans = min(ans, now_ans)
    print((0 if all(t in l for t in target) else ans))


def __starting_point():
    main()

__starting_point()

from itertools import product

N, A, B, C = list(map(int, input().split(' ')))
L = [int(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)


import sys
from itertools import product

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


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

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

    print(ans)
    return


def __starting_point():
    main()

__starting_point()

import sys
input = sys.stdin.readline
N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]
INF = float('inf')

def dfs(i, a, b, c):
    if i == N:
        if a == 0 or b == 0 or c == 0:
            return INF
        else:
            return abs(a-A) + abs(b-B) + abs(c-C)
    ans0 = dfs(i+1, a, b, c)

    ans1 = dfs(i+1, a+L[i], b, c) + (10 if a != 0 else 0)
    ans2 = dfs(i+1, a, b+L[i], c) + (10 if b != 0 else 0)
    ans3 = dfs(i+1, a, b, c+L[i]) + (10 if c != 0 else 0)

    return min(ans0, ans1, ans2, ans3)

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

def __starting_point():
    main()
__starting_point()

from itertools import product


def solve():
    N, A, B, C, *L = list(map(int, open(0).read().split()))

    ans = float("inf")
    for X in product([0, 1, 2, 3], repeat=N):
        tmp = [[] for _ in range(3)]
        [tmp[x - 1].append(L[i]) for i, x in enumerate(X) if x]
        if any(not t for t in tmp):
            continue
        join_cost = sum((len(li) - 1) * 10 for li in tmp)
        expand_cost = sum(abs(sum(t) - a) for t, a in zip(tmp, [A, B, C]))
        ans = min(ans, join_cost + expand_cost)
    return ans


print((solve()))


import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
import itertools

N, *A = mi()
L = [ii() for _ in range(N)]

#A = sorted(A)
sum_a = sum(A)

def dfs(i, a, b, c, use):
    if (0 not in [a, b, c]) and use > 2:
        nonlocal ans
        #abc = sorted([a, b, c])
        #ans = min(ans, (use-3)*10 + sum([abs(abc[i]-A[i]) for i in range(3)]))
        ans = min(ans, (use-3)*10 + abs(a-A[0]) + abs(b-A[1]) + abs(c-A[2]))

    if i > N-1:
        return

    dfs(i+1, a+L[i], b, c, use+1)
    dfs(i+1, a, b+L[i], c, use+1)
    dfs(i+1, a, b, c+L[i], use+1)
    dfs(i+1, a, b, c, use)

ans = float('inf')
dfs(0, 0, 0, 0, 0)

print(ans)



import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
INF = 10**9

def main():
    N, A, B, C = input_nums()
    ll = [int(input()) for _ in range(N)]

    def dfs(idx, a, b, c):
        if idx == N:
            # a,b,cそれぞれ最低1本は必要で合成をしているため、-30が必要
            return abs(a-A)+abs(b-B)+abs(c-C) - 30 if min(a, b, c) > 0 else INF
        ret0 = dfs(idx+1, a, b, c)
        ret1 = dfs(idx+1, a+ll[idx], b, c) + 10
        ret2 = dfs(idx+1, a, b+ll[idx], c) + 10
        ret3 = dfs(idx+1, a, b, c+ll[idx]) + 10
        return min(ret0, ret1, ret2, ret3)

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


def __starting_point():
    main()
__starting_point()

n,a,b,c=list(map(int,input().split()))
l=[]
for i in range(n):
    l.append(int(input()))
ans=100000
for i in range(4**n):
    mp=0
    f=0
    x=[]
    y=[]
    z=[]
    w=[]
    for j in range(n):
        if i%4==0:
            x.append(l[j])
        elif i%4==1:
            y.append(l[j])
        elif i%4==2:
            z.append(l[j])
        else:
            w.append(l[j])
        i=i//4
    if sum(x)==0 or sum(y)==0 or sum(z)==0:
        f=1
    
    X=sum(x)
    Y=sum(y)
    Z=sum(z)
    mp+=(len(x)+len(y)+len(z)-3)*10
    p=[X,Y,Z]
    q=[a,b,c]
    p=sorted(p)
    q=sorted(q)
    mp+=abs(p[0]-q[0])+abs(p[1]-q[1])+abs(p[2]-q[2])
    if f!=1:     
        ans=(min(mp,ans))
print(ans)
    
        

    
        
        
    


import itertools

n, *abc = map(int, input().split())
llst = [int(input()) for _ in range(n)]

ans = 10 ** 10
for abc_lst in itertools.product(range(4), repeat = n):
    tmp = 0
    labc = [[0, 0] for _ in range(3)]
    for i in range(n):
        pos = abc_lst[i]
        if pos == 3:
            continue
        labc[pos][0] += llst[i]
        labc[pos][1] += 1
    if [0, 0] in labc:
        continue
    for i in range(3):
        tmp += abs(abc[i] - labc[i][0])
        tmp += 10 * (labc[i][1] - 1)
    ans = min(ans, tmp)
print(ans)

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

def check(t):
  ca = t.count('a')
  cb = t.count('b')
  cc = t.count('c')
  if ca == 0 or cb == 0 or cc == 0:
    return False
  return True

def calc(t):
  A,B,C=0,0,0
  d = (t.count('a')-1+ t.count('b')-1+t.count('c')-1)*10
  for i,j in enumerate(t):
    if j == 'a':
      A+=l[i]
    elif j == 'b':
      B+=l[i]
    elif j == 'c':
      C+=l[i]
  d += abs(A-a)+abs(B-b)+abs(C-c)
  return d

ary=['a','b','c','d']
take = []
def dfs(s):
  if len(s) == n:
    if check(s):
      take.append(calc(s))
    return
  for i in range(4):
    dfs(s+ary[i])


dfs('')

print (min(take))

import sys
from functools import lru_cache

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


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

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

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

        return min(res0, res1, res2, res3)

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


def __starting_point():
    main()

__starting_point()

n,A,B,C=map(int,input().split())
Q=[int(input()) for ii in range(n)]
inf=10**15
def dfs(now,a,b,c):
    if now==n:
        return abs(a-A)+abs(b-B)+abs(c-C) if 0 not in [a,b,c] else inf
    q1= dfs(now+1,a,b,c)
    q2= dfs(now+1, a+Q[now],b,c)+10
    q3= dfs(now+1, a, b+Q[now], c)+10
    q4 = dfs(now+1,a,b,c+Q[now])+10
    return min(q1,q2,q3,q4)

print(dfs(0,0,0,0)-30)

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

choiceList = []
for i in range(4 ** N):
    choice = [-1 for i in range(N)]
    for j in range (N):
        choice[j] = i // (4 ** j) % 4
    choiceList.append(choice)

minCost = 10 ** 9
for choice in choiceList:
    cost = 10 ** 9
    aList = []
    bList = []
    cList = []
    for i in range(N):
        if choice[i] == 1:
            aList.append(l[i])
        elif choice[i] == 2:
            bList.append(l[i])
        elif choice[i] == 3:
            cList.append(l[i])
    if len(aList) == 0 or len(bList) == 0 or len(cList) == 0:
        cost = 10 ** 9
    else:
        aCost = (len(aList) - 1) * 10 + abs(sum(aList) - A)
        bCost = (len(bList) - 1) * 10 + abs(sum(bList) - B)
        cCost = (len(cList) - 1) * 10 + abs(sum(cList) - C)
        cost = aCost + bCost + cCost
    if minCost > cost:
        minCost = cost

print(minCost)

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

ans = float('inf')
for a in range(1<<N):
    at = []
    for i in range(N):
        if a&(1<<i):
            at.append(L[i])
    if not at: continue
    ap = 10*(len(at)-1) + abs(A - sum(at))
    for b in range(1<<N):
        if a&b: continue
        bt = []
        for i in range(N):
            if b&(1<<i):
                bt.append(L[i])
        if not bt: continue
        bp = 10*(len(bt)-1) + abs(B - sum(bt))
        for c in range(1<<N):
            if (a&c) or (b&c): continue
            ct = []
            for i in range(N):
                if c&(1<<i):
                    ct.append(L[i])
            if not ct: continue
            cp = 10*(len(ct)-1) + abs(C - sum(ct))
            ans = min(ans, ap+bp+cp)
print(ans)

import sys
from itertools import product

input = sys.stdin.readline


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

    ans = float("inf")
    for comb in product(list(range(4)), repeat=N):
        mp = -30
        a = b = c = 0
        for i, j in enumerate(comb):
            if j == 0:
                continue
            elif j == 1:
                a += L[i]
            elif j == 2:
                b += L[i]
            elif j == 3:
                c += L[i]
            mp += 10

        if min(a, b, c) == 0:
            continue

        mp += abs(A - a) + abs(B - b) + abs(C - c)
        if mp < ans:
            ans = mp

    print(ans)


def __starting_point():
    main()

__starting_point()

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

INF = float('inf')

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

    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))

import sys
sys.setrecursionlimit(10**6)
n, A, B, C =map(int,input().split())
l=[]
for i in range(n):
    l.append(int(input()))
inf=10**9
"""
解法
それぞれの竹について「Aの材料」、「Bの材料」、「Cの材料」、「使わない」の4択を決める(4**n通り)
"""
def dfs(cur, a, b, c):
    if cur==n:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else 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))

n,a,b,c=map(int,input().split())
l=[int(input())for _ in range(n)]
def dfs(i,x,y,z):
 if i==n:return abs(a-x)+abs(b-y)+abs(c-z)-30if min(x,y,z)>0else 10**9
 return min(dfs(i+1,x,y,z),dfs(i+1,x+l[i],y,z)+10,dfs(i+1,x,y+l[i],z)+10,dfs(i+1,x,y,z+l[i])+10)
print(dfs(0,0,0,0))

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

def rec(i, a, b, c):
  if i == N:
    if not a or not b or not c: return float('inf')
    return abs(a-A) + abs(b-B) + abs(c-C)
  
  ret = rec(i+1, a, b, c)
  
  ret = min(ret, rec(i+1, a+L[i], b, c) + (10 if a else 0))
  ret = min(ret, rec(i+1, a, b+L[i], c) + (10 if b else 0))
  ret = min(ret, rec(i+1, a, b, c+L[i]) + (10 if c else 0))
  
  return ret

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

from itertools import product


def solve():
    N, A, B, C, *L = list(map(int, open(0).read().split()))

    ans = float("inf")
    for X in product([0, 1], repeat=N):
        tmp = [L[i] for i in range(N) if X[i]]
        if len(tmp) < 3:
            continue
        for Y in product([0, 1, 2], repeat=len(tmp)):
            tmp_inner = [[] for _ in range(3)]
            for j, y in enumerate(Y):
                tmp_inner[y].append(tmp[j])
            if all(t for t in tmp_inner):
                join_cost = sum((len(li) - 1) * 10 for li in tmp_inner)
                expand_cost = sum(abs(sum(t) - a) for t, a in zip(tmp_inner, [A, B, C]))
                ans = min(ans, join_cost + expand_cost)
    return ans


print((solve()))


import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

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

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

# def main():
  

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

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

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

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

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

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

    return min(answer,sm)

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

  return answer

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


from itertools import product
n, a, b, c = list(map(int, input().split()))
L = [int(input())for _ in range(n)]

INF = 10**18
ans = INF
for subset in product(list(range(4)), repeat=n):
    cost = 0
    ABC = [[]for _ in range(3)]
    for i, s in enumerate(subset):
        if not s:
            continue
        ABC[s-1].append(L[i])
    if any(not X for X in ABC):
        continue
    for x, X in zip((a, b, c), ABC):
        cost += (len(X)-1)*10
        cost += abs(x-sum(X))
    if cost < ans:
        ans = cost

print(ans)


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


n,a,b,c = map(int, input().split())
l = [int(input()) for _ in range(n)]
ans = 10**9
dfs(0,0,0,0,0,0,0)
print(ans)

N,A,B,C = map(int,input().split())

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

# L本の竹を、A,B,C,0(使わない)に振り分ける全探索 4^N = 約60000通り

ans = 10 ** 10
import itertools
for prod in itertools.product(range(4), repeat = N):
  bamboo = [0] * 4
  mp = 0
  for i in range(len(prod)):
    if prod[i] == 0:
      continue
    if bamboo[prod[i]] != 0:
      mp += 10
    bamboo[prod[i]] += L[i]
  if 0 in bamboo[1:]:
    continue
  mp += abs(A - bamboo[1]) + abs(B - bamboo[2]) + abs(C - bamboo[3])
  if ans > mp:
    ans = mp
    
print(ans)

import sys
from itertools import product
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, A, B, C = list(map(int, input().split()))
    goal = [A, B, C]
    L = list(int(input()) for _ in range(n))

    res = f_inf
    for pattern in product([0, 1, 2, 3], repeat=n):
        cnt = [0] * 3
        length = [0] * 3
        for idx, p in enumerate(pattern):
            if p != 0:
                length[p - 1] += L[idx]
                cnt[p - 1] += 1
        mp = 0
        for i in range(3):
            if cnt[i] == 0:
                break
            mp += abs(goal[i] - length[i]) + (cnt[i] - 1) * 10
        else:
            res = min(res, mp)
    print(res)


def __starting_point():
    resolve()

__starting_point()

from itertools import product
N,A,B,C=map(int,input().split())
l=[]
for _ in range(N):
    l.append(int(input()))
ans=10**18
for i in product(range(4),repeat=N):
    mp=0
    bamboo=[0,0,0]
    for j in range(N):
        s=i[j]
        if s==3:
            continue
        else:
            if bamboo[s]!=0:
                mp+=10
            bamboo[s]+=l[j]
    if bamboo[0]==0 or bamboo[1]==0 or bamboo[2]==0:
        continue
    mp+=abs(A-bamboo[0])
    mp+=abs(B-bamboo[1])
    mp+=abs(C-bamboo[2])
    ans=min(ans,mp)
print(ans)

import sys
from itertools import product

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


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

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

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

        return min(res0, res1, res2, res3)

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


def __starting_point():
    main()

__starting_point()

import sys
input = sys.stdin.readline
N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]
INF = float('inf')
def dfs(i,a,b,c):
    # さいごまで到達したときの操作  
    if i == N:
        if a==0 or b==0 or c==0:
            return INF
        else:
            return abs(a-A) + abs(b-B) + abs(c-C)
    # すべての手順
    ans0 = dfs(i+1, a, b, c)
    ans1 = dfs(i+1, a+L[i], b, c) + (10 if a != 0 else 0)
    ans2 = dfs(i+1, a, b+L[i], c) + (10 if b != 0 else 0)
    ans3 = dfs(i+1, a, b, c+L[i]) + (10 if c != 0 else 0)
    
    ans = min(ans0, ans1, ans2, ans3)
    return ans

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

def __starting_point():
    main()
__starting_point()

from itertools import product
N, A, B, C = map(int, input().split())
abc = [C, B, A]
lst = [int(input()) for _ in range(N)]

ans = []
for l in product([0, 1, 2, 3], repeat=N):
    cnt = [[], [], [], []]
    for i, ll in enumerate(l):
        cnt[ll].append(lst[i])
    mp = 0
    p = []
    for i in cnt[:3]:
        if len(i) != 0: mp += (len(i) - 1) * 10
        p.append(sum(i))
    p.sort()
    if p[0]!=0:
        for i in range(3):
            mp += abs(p[i] - abc[i])
        ans.append(mp)
print(min(ans))

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
import itertools

N, *A = mi()
L = [ii() for _ in range(N)]
L_ = [L[i] for i in range(N)]
N_ = N

A = sorted(A)
#sum_l = sum(L)
tmp = [0] * 3
ans = float('inf')

for k in itertools.product([0,1], repeat=N_):
    N = sum(k)
    if N < 3:
        continue
    L = []
    for x in range(N_):
        if k[x]:
            L.append(L_[x]*k[x])
    #L = [L_[x]*k[x] for x in range(N_)]
    sum_l = sum(L)

    for i in range(1, N+1):
        for koho_i in range(1, 2**i):
            for koho_j in range(1, 2**i):
                j = i
                #print(koho_i, koho_j)
                if koho_i & koho_j:
                    continue
                #tmp[0] = [L[x]*koho_i[x] for x in range(i)]
                tmp[0] = sum([L[x]*min((koho_i & 1<<x), 1) for x in range(i)])
                #tmp[1] = [L[x]*koho_j[x] for x in range(j)]
                tmp[1] = sum([L[x]*min((koho_j & 1<<x), 1) for x in range(j)])
                tmp[2] = sum_l - tmp[0] - tmp[1]
                #print(tmp)

                if 0 in tmp:
                    continue

                tmp = sorted(tmp)
                cost = (N-3) * 10 + sum([abs(tmp[x]-A[x]) for x in range(3)])
                #if cost < ans:
                    #print(tmp, cost, N)
                #if tmp[0] == 80 and tmp[1] == 91 and tmp[2] == 98:
                    #print(cost)
                ans = min(ans, cost)

print(ans)


def main():
    n, a, b, c = list(map(int, input().split()))
    L = [int(input()) for _ in range(n)]
    INF = 1000000
    def dfs(i, la, lb, lc):
        if i == n:
            return abs(la - a) + abs(lb - b) + abs(lc - c) if min(la, lb, lc) > 0 else INF
        res = []
        res.append(dfs(i + 1, la, lb, lc))
        res.append(dfs(i + 1, la + L[i], lb, lc) + 10 if la != 0 else dfs(i + 1, la + L[i], lb, lc))
        res.append(dfs(i + 1, la, lb + L[i], lc) + 10 if lb != 0 else dfs(i + 1, la, lb + L[i], lc))
        res.append(dfs(i + 1, la, lb, lc + L[i]) + 10 if lc != 0 else dfs(i + 1, la, lb, lc + L[i]))
        return min(res)
    print(dfs(0, 0, 0, 0))

def __starting_point():
    main()
__starting_point()

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

import itertools

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

INF = 10 ** 9
#Target = [(1,2,2,2,3)]
ans = INF
for T in Target:
    A_sum = 0
    B_sum = 0
    C_sum = 0
    A_cost = 0
    B_cost = 0
    C_cost = 0
    for i in range(N):
        if T[i] == 0: continue
        if T[i] == 1:
            if A_sum == 0:
                A_sum += L_list[i]
            else:
                A_sum += L_list[i]
                A_cost += 10
        if T[i] == 2:
            if B_sum == 0:
                B_sum += L_list[i]
            else:
                B_sum += L_list[i]
                B_cost += 10
        if T[i] == 3:
            if C_sum == 0:
                C_sum += L_list[i]
            else:
                C_sum += L_list[i]
                C_cost += 10

    if min(A_sum, B_sum, C_sum) == 0: continue

    ans = min(ans, abs(A - A_sum)+A_cost + abs(B - B_sum)+B_cost + abs(C - C_sum)+C_cost)
print(ans)


N, A, B, C = list(map(int, input().split()))
l = [int(input()) for i in range(N)]
 
INF = float('inf')
ans = INF
 
def dfs(a, b, c, n, cost):
    nonlocal ans
    if n == N:
        cost += abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else INF
        ans = min(ans, cost)
        return
    dfs(a, b, c, n+1, cost)
    dfs(a+l[n], b, c, n+1, cost+10)
    dfs(a, b+l[n], c, n+1, cost+10)
    dfs(a, b, c+l[n], n+1, cost+10)
 
dfs(0, 0, 0, 0, 0)
print(ans)


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

def kadomatsu(li,x):
    cost = 0
    cost += 10*(len(li)-1)
    cost += abs(sum(li)-x)
    return cost

ansli = []

for i in range(4**n):
    #print(i,end = " ")
    #memo = i
    amari = []
    while True:
        if i >= 4:
            amari.append(i%4)
            i = i//4
        else:
            amari.append(i)
            break
    gyaku = amari[::-1]
    #print(gyaku,end=" ")
    gya = [0]*(n - len(gyaku)) + gyaku
    #print(gya,end = " ")
    al = []
    bl = []
    cl = []
    for j in range(n):
        if gya[j] == 1:
            al += [l[j]]
        elif gya[j] == 2:
            bl += [l[j]]
        elif gya[j] == 3:
            cl += [l[j]]
    if al and bl and cl:
        ans = kadomatsu(al,a) + kadomatsu(bl,b) + kadomatsu(cl,c)
        ansli += [ans]
        #print(memo,gya,al,bl,cl)
print(min(ansli))

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


ans = dfs(0, 0, 0, 0)
print(ans)

# coding: utf-8

# https://atcoder.jp/contests/abc119


def main():
    N, A, B, C = list(map(int, input().split()))
    ls = [None] * N
    for i in range(N):
        ls[i] = int(input())

    abc_mp = []

    def rec(i, a, b, c, mp, ls):
        if i == len(ls):
            if a > 0 and b > 0 and c > 0:
                abc_mp.append([a, b, c, mp-30])
        else:
            rec(i+1, a+ls[i], b, c, mp+10, ls)
            rec(i+1, a, b+ls[i], c, mp+10, ls)
            rec(i+1, a, b, c+ls[i], mp+10, ls)
            rec(i+1, a, b, c, mp, ls)

    rec(0, 0, 0, 0, 0, ls)
    a0, b0, c0, mp0 = abc_mp[0]
    ans = mp0 + abs(A-a0) + abs(B-b0) + abs(C-c0)
    for a, b, c, mp in abc_mp:
        cand = mp + abs(A-a) + abs(B-b) + abs(C-c)
        if cand < ans:
            ans = cand

    return ans


print((main()))


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


def test(n, a, b, c, na, nb, nc):
    """
    :param n: 使用している竹の本数
    :param a: 竹aの長さ
    :param b: 竹bの長さ
    :param c: 竹cの長さ
    :param na: 竹aに使用した本数
    :param nb: 竹bに使用した本数
    :param nc: 竹cに使用した本数
    :return: 消費MP
    """
    if n == N:
        # 最終MPの確定
        if min(na, nb, nc) == 0:
            return 10**9
        else:
            mp = 0
            mp += (na-1) * 10 if na else 0
            mp += (nb-1) * 10 if nb else 0
            mp += (nc-1) * 10 if nc else 0
            mp += abs(A-a) + abs(B-b) + abs(C-c)
            return mp
    else:
        mp1 = test(n+1, a, b, c, na, nb, nc)  # 使用しない
        mp2 = test(n+1, a+L[n], b, c, na+1, nb, nc)  # 竹aに適用
        mp3 = test(n+1, a, b+L[n], c, na, nb+1, nc)  # 竹bに適用
        mp4 = test(n+1, a, b, c+L[n], na, nb, nc+1)  # 竹cに適用
        return min(mp1, mp2, mp3, mp4)


print((test(0, 0, 0, 0, 0, 0, 0)))


n,a,b,c=map(int,input().split())
l=[]
for _ in range(n):
    lt=int(input())
    l.append(lt)
from itertools import product
count=10**10
for i in product([0,1,2,3],repeat=n):
    if i.count(0)>=1 and i.count(2)>=1 and i.count(1)>=1:
    
        temp=0
        at=0
        bt=0
        ct=0
        for j in range(n):
            if i[j]==0:
                at+=l[j]
                temp+=1

            elif i[j]==1:
                bt+=l[j]
                temp+=1
            
            elif i[j]==2:
                ct+=l[j]
                temp+=1
        count=min(count,abs(a-at)+abs(b-bt)+abs(c-ct)+10*(temp-3))
        
print(count)

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

l = [0] * N
for i in range(N):
    l[i] = int(input())

import numpy
mpp = 10**10
L = [0] * 3
t = [-10] * 3

for i in range(1, 4**N):
    b = numpy.base_repr(i, 4, N)[-N:]
    L = [A, B, C]
    t = [-10] * 3
    if "1" not in b or "2" not in b or "3" not in b:
        continue
    #print(b)
    for j in range(N):
        for k in range(3):
            if b[j] == str(k + 1):
                L[k] -= l[j]
                t[k] += 10
    mpp = min(mpp, sum(t) + sum([abs(x) for x in L]))

print(mpp)



n,a,b,c,*l=map(int,open(0).read().split())
def dfs(x,y,z,r):
  if r==n:
    return abs(a-x)+abs(b-y)+abs(c-z)-30 if min(x,y,z)>0 else 10**9
  return min(
    dfs(x+l[r],y,z,r+1)+10,
    dfs(x,y+l[r],z,r+1)+10,
    dfs(x,y,z+l[r],r+1)+10,
    dfs(x,y,z,r+1)
  )
print(dfs(0,0,0,0))

n, a, b, c = map(int,input().split())
l = []
for i in range(n):
    l.append(int(input()))
ans = 10**9    
for ci in range(4**n):
    ci_ = [-1] * n
    cnt = [0] * 3
    ca, cb, cc = 0, 0, 0
    for cj in range(n):
        cx = ci & 3
        if cx == 0:
            ca += l[cj]
            cnt[0] += 1 
        elif cx == 1:
            cb += l[cj]
            cnt[1] += 1 
        elif cx == 2:
            cc += l[cj]
            cnt[2] += 1 
        ci >>= 2
    if ca == 0 or cb == 0 or cc == 0:
        continue
    
    cost = 0
    for i in range(3):
        if cnt[i] > 1:
            cost += 10 * (cnt[i]-1)
    cost += abs(a-ca) + abs(b-cb) + abs(c-cc)
    ans = min(ans, cost)
print(ans)

n,A,B,C=map(int,input().split())
Q=[int(input()) for ii in range(n)]
inf=10**15
def dfs(now,a,b,c):
    if now==n:
        return abs(a-A)+abs(b-B)+abs(c-C) if 0 not in [a,b,c] else inf
    q1= dfs(now+1,a,b,c)
    q2= dfs(now+1, a+Q[now],b,c)+10
    q3= dfs(now+1, a, b+Q[now], c)+10
    q4 = dfs(now+1,a,b,c+Q[now])+10
    return min(q1,q2,q3,q4)
 
print(dfs(0,0,0,0)-30)

from itertools import *
N,A,B,C = map(int, input().split())
L = [int(input()) for n in range(N)]
ans = []

for i in product(range(4),repeat=N):
  a = 0
  b = 0
  c = 0
  d = 0
  for j in range(N):
    if i[j]:
      d+=1
      if i[j]==1:
        a+=L[j]
      elif i[j]==2:
        b+=L[j]
      else:
        c+=L[j]
  if a*b*c:
    ans+=[abs(A-a)+abs(B-b)+abs(C-c)+10*(d-3)]

print(min(ans))

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

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

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

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

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

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

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


# とりあえず解説を見ずに無理矢理解く。
# 全ての竹を「Aに使う・Bに使う・Cに使う・使わない」のどれかに振り分ける方法は
# 4**8 = 2**16 ≒ 64000なので全通り探索できる。
# C < B < Aなので、合成した後に長い順にすれば6分の1だけ調べれば良いが、該当の6分の1だけを抜き出すのは難しい
# どれかに使うが空集合になってるのは除外。

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

ans = 10**10

for usage_info in itertools.product(list(range(4)), repeat=n):

    mp = 0
    length = [0, 0, 0]
    for idx, usage in enumerate(usage_info):
        if usage == 3:
            continue
        if length[usage] > 0:
            mp += 10  # 合成魔法
        length[usage] += nums[idx]
    if min(length) == 0:
        continue

    mp += abs(length[0] - a) + abs(length[1] - b) + abs(length[2] - c)  # 延長、短縮魔法
    ans = min(ans, mp)

print(ans)


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

from itertools import product

P=product(list(range(4)),repeat=N)

ans=1000000000
for p in P:
    A_len=0
    B_len=0
    C_len=0
    temp=0
    for i in range(N):
        n=int(p[i])
        if n==3:
            if A_len!=0:
                temp+=10
            A_len+=l[i]
        elif n==2:
            if B_len!=0:
                temp+=10
            B_len+=l[i]
        elif n==1:
            if C_len!=0:
                temp+=10
            C_len+=l[i]

    if A_len!=0 and B_len!=0 and C_len!=0:
        temp+=abs(A-A_len)
        temp+=abs(B-B_len)
        temp+=abs(C-C_len)

        ans=min(ans,temp)

print(ans)



from functools import lru_cache
N, A, B, C, *L = list(map(int, open(0).read().split()))


@lru_cache(None)
def popcnt(n):
    return bin(n).count('1')


@lru_cache(None)
def synth(bit):
    length = 0
    for i in range(N):
        if bit >> i & 1:
            length += L[i]
    return length


ans = 1 << 60
for bit1 in range(1, 1 << N):
    if popcnt(bit1) >= N-1:
        continue
    length1 = synth(bit1)

    for bit2 in range(1, 1 << N):
        if bit1 & bit2:
            continue
        if popcnt(bit1 | bit2) == N:
            continue
        length2 = synth(bit2)

        for bit3 in range(1, 1 << N):
            if bit1 & bit3 or bit2 & bit3:
                continue

            length3 = synth(bit3)
            c, b, a = sorted([length1, length2, length3])

            cost = 10*(popcnt(bit1 | bit2 | bit3)-3) + abs(C-c) + abs(B-b) + abs(A-a)
            if cost < ans:
                ans = cost

print(ans)


n,a,b,c,*L = 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)

import itertools

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

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

ans = 10**10
# [竹1の選択, 竹2の選択, ..., 竹Nの選択]
# 4**8==65536
for x in itertools.product([0, 1, 2, 3], repeat=N):
    # [不使用の竹の合計長さ、Aに使用する竹の合計長さ、Bに...、Cに...]
    bamboo = [0] * 4
    tmp = 0
    for i in range(N):
        # 始めて選ぶ場合はコストがかからない
        if x[i] in [1, 2, 3] and bamboo[x[i]] > 0:
            tmp += 10
        bamboo[x[i]] += l[i]

    # A,B,Cそれぞれについて、1本以上使う必要がある
    if 0 in bamboo[1:]:
        continue
    # 延長魔法 or 短縮魔法で調整
    tmp += abs(bamboo[1] - A) + abs(bamboo[2] - B) + abs(bamboo[3] - C)

    ans = min(ans, tmp)

print(ans)


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

def rec(i, a, b, c):
  if i == N:
    if not a or not b or not c: return float('inf')
    return abs(a-A) + abs(b-B) + abs(c-C)
  
  ret = rec(i+1, a, b, c)
  
  ret = min(ret, rec(i+1, a+L[i], b, c) + (10 if a else 0))
  ret = min(ret, rec(i+1, a, b+L[i], c) + (10 if b else 0))
  ret = min(ret, rec(i+1, a, b, c+L[i]) + (10 if c else 0))
  
  return ret

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


N, A, B, C = list(map(int, input().split()))
L = [int(input()) for _ in range(N)]
def rec(itr, a, b, c, mp):
    if itr == N:
        if a == 0 or b == 0 or c == 0:
            return 10 ** 9
        return abs(a - A) + abs(b - B) + abs(c - C) + mp - 30
    res = rec(itr + 1, a, b, c, mp)
    res = min(res, rec(itr + 1, a + L[itr], b, c, mp) + 10)
    res = min(res, rec(itr + 1, a, b + L[itr], c, mp) + 10)
    res = min(res, rec(itr + 1, a, b, c + L[itr], mp) + 10)
    return res
print((rec(0, 0, 0, 0, 0)))


from itertools import product
n, a, b, c = list(map(int, input().split()))
l = [int(input()) for _ in range(n)]
ans = 1001001001
for x in product(list(range(4)), repeat=n):
    s = [0] * 4
    t = -3
    for i in range(n):
        t += x[i] < 3
        s[x[i]] += l[i]
    s.pop()
    if 0 in s:
        continue
    ans = min(ans, t * 10 + abs(s[0] - a) + abs(s[1] - b) + abs(s[2] - c))
print(ans)


# N番目の竹をA,B,Cのいずれかに使うorどれにも使わないの全探索
# 4 ^ 8 = 60000強

import sys
readline = sys.stdin.readline

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

ans = 10 ** 10
import itertools
for prod in itertools.product(range(4),repeat = N):
  if len(set(prod) & set(range(3))) != 3:
    continue
  take = [0] * 3
  cost = 0
  for i in range(len(prod)):
    if prod[i] == 3:
      continue
    if take[prod[i]] != 0:
      cost += 10
    take[prod[i]] += L[i]
  cost += abs(A - take[0]) + abs(B - take[1]) + abs(C - take[2])
  if ans > cost:
    ans = cost

print(ans)

import sys
sys.setrecursionlimit(10**8)
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 li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
import itertools

N, *A = mi()
L = [ii() for _ in range(N)]

A = sorted(A)
sum_a = sum(A)

def dfs(i, a, b, c, use):
    if (0 not in [a, b, c]) and use > 2:
        nonlocal ans
        abc = sorted([a, b, c])
        ans = min(ans, (use-3)*10 + sum([abs(abc[i]-A[i]) for i in range(3)]))

    if i > N-1:
        return

    dfs(i+1, a+L[i], b, c, use+1)
    dfs(i+1, a, b+L[i], c, use+1)
    dfs(i+1, a, b, c+L[i], use+1)
    dfs(i+1, a, b, c, use)

ans = float('inf')
dfs(0, 0, 0, 0, 0)

print(ans)

N,A,B,C = map(int,input().split())
l = [int(input()) for n in range(N)]
inf = 10 ** 18

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

    res0 = dfs(cur+1,a,b,c)
    res1 = dfs(cur+1,a+l[cur],b,c)+10
    res2 = dfs(cur+1,a,b+l[cur],c)+10
    res3 = dfs(cur+1,a,b,c+l[cur])+10
    return min(res0,res1,res2,res3)
print(dfs(0,0,0,0))

N,A,B,C=map(int,input().split())
l=[int(input()) for _ in range(N)]
inf=10**18
def dfs(cur,a,b,c):
  if cur==N:
    if min(a,b,c)>0:
      return abs(A-a)+abs(B-b)+abs(C-c)-30
    else:
      return inf
  res0 = dfs(cur+1,a,b,c)
  res1 = dfs(cur+1,a+l[cur],b,c)+10
  res2 = dfs(cur+1,a,b+l[cur],c)+10
  res3 = dfs(cur+1,a,b,c+l[cur])+10
  return min(res0,res1,res2,res3)
print(dfs(0,0,0,0))

N, A, B, C = list(map(int, input().split()))
l = [int(input()) for i in range(N)]
def dfs(cur,a,b,c):
    if cur ==N:
        return abs(a-A) + abs(b-B) + abs(c-C) -30 if min(a,b,c) > 0 else float('inf')
    r1 = dfs(cur+1,a,b,c)
    r2 = dfs(cur+1,a+l[cur],b,c) +10
    r3 = dfs(cur+1,a,b+l[cur],c) + 10
    r4 = dfs(cur+1,a,b,c+l[cur]) + 10
    return min(r1,r2,r3,r4)
print((dfs(0,0,0,0)))
#全てのバリエーション試す、dfs


# C MP消費を抑えるにはABCとの差が小さけれは良い
n, A, B, C = list(map(int, input().split()))
l = [int(input()) for _ in range(n)]
INF = 10**9


def dfs(now, a, b, c):
    if now == n:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    # 方法１　１つ飛ばす
    way1 = dfs(now + 1, a, b, c)
    # 方法２　合成魔法(MP10)
    way2 = dfs(now + 1, a + l[now], b, c)+10
    way3 = dfs(now + 1, a, b + l[now], c)+10
    way4 = dfs(now + 1, a, b, c + l[now])+10
    return min(way1, way2, way3, way4)


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


import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return list(map(int, input().split()))
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n, A,B,C = i_map()

    l = [i_input() for i in range(n)]

    def dfs(cur, a,b,c):
        if cur==n:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a,b,c) > 0 else 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)))


def __starting_point():
    main()

__starting_point()

import sys
sys.setrecursionlimit(10**7)
n,A,B,C = map(int,input().split())
L_ls = [int(input()) for _ in range(n)]

# dfs(i,a,b,c) := i番目の竹のまえの時点で、A用の長さがa, B用の長さがb, C用の長さがcだった時の、それ以降の分岐での最初コスト
def dfs(i,a,b,c):
    if i == n:
        if a==0 or b == 0 or c == 0:
            return float('inf')
        else:
            return abs(a-A) + abs(b-B) + abs(c-C)
    
    Min = dfs(i+1,a,b,c)

    if a == 0:
        Min = min(Min,dfs(i+1,a+L_ls[i],b,c))
    else:
        Min = min(Min,dfs(i+1,a+L_ls[i],b,c)+10)
    
    if b == 0:
        Min = min(Min,dfs(i+1,a,b+L_ls[i],c))
    else:
        Min = min(Min,dfs(i+1,a,b+L_ls[i],c)+10)
    
    if c == 0:
        Min = min(Min,dfs(i+1,a,b,c+L_ls[i]))
    else:
        Min = min(Min,dfs(i+1,a,b,c+L_ls[i])+10)
    
    return Min
print(dfs(0,0,0,0))

from itertools import product
n, a, b, c = map(int, input().split())
l = [int(input()) for i in range(n)]

ans = float('inf')
for choice in product([0, 1, 2, 3], repeat=n):
    items = [0] * 3
    totals = [0] * 3
    temp = 0
    if min([choice.count(i) for i in range(3)]) == 0: continue
    for i, ch in enumerate(choice):
        if ch == 3: continue
        totals[ch] += l[i]
        items[ch] += 1
        if items[ch] > 1:
            temp += 10
    temp+=abs(a-totals[0])
    temp+=abs(b-totals[1])
    temp+=abs(c-totals[2])
    ans = min(ans, temp)
print(ans)

N, A, B, C = map(int, input().split())
from itertools import product
l = [int(input()) for i in range(N)]
ans = []
for i in product(range(4), repeat=N):
  a = 0
  b = 0
  c = 0
  d = 0
  for j in range(N):
    if i[j]:
      d += 1
      if i[j] == 1:
        a += l[j]
      elif i[j] == 2:
        b += l[j]
      else:
        c += l[j]
  if a * b * c:
    ans += [abs(A - a) + abs(B - b) + abs(C - c) + (d - 3) * 10]
print(min(ans))

import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,A,B,C = I()
l = [i() for _ in range(N)]
def dfs(cur,a,b,c):
    if cur == N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c) > 0 else 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))

N,A,B,C= list(map(int,input().split()))
l=[]
Inf=float("Inf")
for i in range(N):l.append(int(input()))
def Answer(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 Inf
   pt1=Answer(cnt+1,a,b,c)
   pt2=Answer(cnt+1,a+l[cnt],b,c)+10
   pt3=Answer(cnt+1,a,b+l[cnt],c)+10
   pt4=Answer(cnt+1,a,b,c+l[cnt])+10
   return(min(pt1,pt2,pt3,pt4))
print(Answer(0,0,0,0))

from itertools import product

N, *ABC = map(int, input().split())

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

ans = 10**9
for X in product((0, 1, 2, 3), repeat=N):
  cnt, K, temp = [0]*4, [0]*4, 0
  for i in range(N):
    cnt[X[i]] += 1
    K[X[i]] += L[i]
  if min(cnt[1:]) == 0:
    continue
  for i in range(3):
    temp += abs(ABC[i] - K[i+1])
    temp += 10 * max(cnt[i+1]-1, 0)
  ans = min(ans, temp)

print(ans)

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

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

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

	return min(ret0, ret1, ret2, ret3)

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

import itertools
N,A,B,C=map(int, input().split())
l=[int(input()) for _ in range(N)]
pattern=["a","b","c","N"]

lcombi=itertools.product(pattern,repeat=N)

ans=(1000)**3
for lc in list(lcombi):
	Alen=0
	Blen=0
	Clen=0
	Acost=0
	Bcost=0
	Ccost=0
	
	if ("a" not in lc) or("b" not in lc) or("c" not in lc):
		continue
	else:
		for i in range(N):
			if lc[i]=="a":
				if Alen==0:Alen+=l[i]
				else:
					Alen+=l[i]
					Acost+=10
			elif lc[i]=="b":
				if Blen==0:Blen+=l[i]
				else:
					Blen+=l[i]
					Bcost+=10
			elif lc[i]=="c":
				if Clen==0:Clen+=l[i]
				else:
					Clen+=l[i]
					Ccost+=10
		Acost+=abs(Alen-A)
		Bcost+=abs(Blen-B)
		Ccost+=abs(Clen-C)
		ans=min(ans,Acost+Bcost+Ccost)

print(ans)

N,A,B,C=map(int,input().split())
L=[int(input()) for i in range(N)]
R=[0]*N
ans=10**9
def myadd(i):
    if R[i]==3:
        R[i]=0
        myadd(i+1)
    else:
        R[i]+=1
for i in range(4**N-1):
    myadd(0)
    if 1 in R and 2 in R and 3 in R:
        tmp=-30
        t1,t2,t3=0,0,0
        for j in range(N):
            if R[j]==0:
                continue
            if R[j]==1:
                t1+=L[j]
            elif R[j]==2:
                t2+=L[j]
            elif R[j]==3:
                t3+=L[j]
            tmp+=10
        tmp+=abs(A-t1)+abs(B-t2)+abs(C-t3)
        ans=min(tmp,ans)
print(ans)

n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]
ans = 100000000000
for i in range(4**n):
    A = []
    B = []
    C = []
    D = []
    current = 0
    for j in range(n):
        if i>>(2*j)&3 == 0:
            A.append(l[j])
        elif i>>(2*j)&3 == 1:
            B.append(l[j])
        elif i>>(2*j)&3 == 2:
            C.append(l[j])
        elif i>>(2*j)&3 == 3:
            D.append(l[j])
    if A and B and C:
        current += (len(A)-1)*10 + abs(sum(A)-a)
        current += (len(B)-1)*10 + abs(sum(B)-b)
        current += (len(C)-1)*10 + abs(sum(C)-c)
        ans = min(ans, current)
print(ans)

from itertools import product

INF = 10 ** 9

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


def estimate(lst):
    if any(not p for p in lst):
        return INF

    ret = 0
    for p, g in zip(lst, A):
        ret += abs(g - sum(p)) + (len(p) - 1) * 10
    return ret


ans = INF
for prd in product(list(range(4)), repeat=N):
    pieces = [[] for _ in range(3)]
    for bamboo_ind, target_kadomatsu in enumerate(prd):
        if target_kadomatsu == 3: continue
        pieces[target_kadomatsu].append(L[bamboo_ind])
    if ans > (res := estimate(pieces)):
        ans = res
print(ans)


from itertools import product, permutations

N, A, B, C = list(map(int, input().split(' ')))
L = [int(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)


N, A, B, C = map(int, input().split())
l = []
for i in range(N):
    l.append(int(input()))
    
def dfs(bamboo, a, b, c):
    if bamboo == N:
        if min(a, b, c) > 0:
            return abs(A-a) + abs(B-b) + abs(C-c) - 30
        else:
            return 10**10
    else:
        ans1 = dfs(bamboo+1, a, b, c)
        ans2 = dfs(bamboo+1, a+l[bamboo], b, c) + 10
        ans3 = dfs(bamboo+1, a, b+l[bamboo], c) + 10
        ans4 = dfs(bamboo+1, a, b, c+l[bamboo]) + 10
        return min(ans1, ans2, ans3, ans4)
        
print(dfs(0, 0, 0, 0))

N,A,B,C = map(int,input().split())

L = [int(input()) for _ in range(N)]
    
INF = 10**9

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

import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, A, B, C = LI()
    ABC = (A, B, C)
    l = [I() for _ in range(N)]

    # A, B, Cに使う、捨てる、の4通り
    ans = INF
    for i in itertools.product(list(range(4)), repeat=N):
        a_cnt = i.count(0)
        b_cnt = i.count(1)
        c_cnt = i.count(2)
        if a_cnt > 0 and b_cnt > 0 and c_cnt > 0:
            # 合成魔法
            mp = 10 * (a_cnt + b_cnt + c_cnt - 3)
            # 延長短縮魔法
            len = [0] * 3
            for j in range(N):
                if 0 <= i[j] < 3:
                    len[i[j]] += l[j]
            mp += sum([abs(j - k) for j, k in zip(ABC, len)])
            ans = min(mp, ans)

    print(ans)

def __starting_point():
    resolve()

__starting_point()

n,a,b,c=list(map(int,input().split()))
L=[int(input()) for _ in range(n)]
ans=10**9
for x in range(4**n):
    A,B,C=0,0,0
    cost=0
    for i in range(n):
        r=x%4
        x//=4
        if r==1:
            A+=L[i]
        elif r==2:
            B+=L[i]
        elif r==3:
            C+=L[i]
        if r>0:
            cost+=10
    if A==0 or B==0 or C==0:
        continue
    cost+=-30+abs(A-a)+abs(B-b)+abs(C-c)
    ans=min(ans,cost)
print(ans)


from itertools import product
p=4
n,a,b,c=map(int,input().split())
banboo=[0]*n
for i in range(n):
    banboo[i]=int(input())

Bit_4=list(product(range(p),repeat=n))
ans=10**6
for Bi in Bit_4:
    tmp=[0]*4
    magic=0
    if 1 in Bi and 2 in Bi and 3 in Bi:
        for i in range(n):
            tmp[Bi[i]]+=banboo[i]
            if tmp[Bi[i]]!=banboo[i] and Bi[i]!=0:
                magic+=10
        magic+=abs(tmp[1]-a)
        magic+=abs(tmp[2]-b)
        magic+=abs(tmp[3]-c)
        ans=min(magic,ans)
print(ans)

n, a, b, c = map(int, input().split())
bamboos = []
for i in range(n):
    bamboo = int(input())
    bamboos.append(bamboo)

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

def calc_score(group, target):
    score = 0
    if len(group) > 1:
        score += 10 * (len(group) - 1)
    length = sum(group)
    score += abs(length - target)
    return score

min_score = 10**12
for i in range(4**n):
    num = Base_10_to_n(i, 4).zfill(n)
    score = 0
    group_A = []
    group_B = []
    group_C = []
    for j in range(n):
        if num[j] == '1':
            group_A.append(bamboos[j])
        elif num[j] == '2':
            group_B.append(bamboos[j])
        elif num[j] == '3':
            group_C.append(bamboos[j])
    if len(group_A) == 0 or len(group_B) == 0 or len(group_C) == 0:
        continue
    else:
        score += calc_score(group_A, a)
        score += calc_score(group_B, b)
        score += calc_score(group_C, c)

    if score < min_score:
        min_score = score

print(min_score)

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

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 INF
        #最初は0から始めていて不要な処理が一回あるため-30する。
    res0 = dfs(cnt + 1,a,b,c)
    res1 = dfs(cnt + 1,a + l[cnt],b,c) + 10
    res2 = dfs(cnt + 1,a,b + l[cnt],c) + 10
    res3 = dfs(cnt + 1,a,b,c + l[cnt]) + 10
    return min(res0,res1,res2,res3)

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

def to4(num):
    if num//4 < 1:
        return str(num)
    else:
        return to4(num//4)+str(num%4)
    
def SyntheticKadomatsu():
    idata = list(map(int, input().split()))
    l = [int(input()) for _ in range(idata[0])]
    ans = float('inf')
    # bit全探索
    for i in range(4**idata[0]):
        bits = [0]*4
        tmp = 0
        num = to4(i).zfill(idata[0])
        for j in range(idata[0]):
            v = int(num[-j-1])
            if bits[v] != 0 and v != 3:
                tmp += 10
            bits[v] += l[j]
        if 0 in set(bits[:-1]):
            continue
        for j in range(3):
            tmp += abs(bits[j]-idata[j+1])
        ans = min(ans, tmp)
    print(ans)

def __starting_point():
    SyntheticKadomatsu()
    

__starting_point()

import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
	N, A, B, C = NMI()
	L = [NI() for _ in range(N)]

	def dfs(bamboo, a, b, c):
		if bamboo == N:
			if a*b*c == 0:
				return 10**100
			a, b, c = sorted([a, b, c], reverse=True)
			res = abs(A-a) + abs(B-b) + abs(C-c)
			return res

		res = 10**100

		res = min(res, dfs(bamboo + 1, a + L[bamboo], b, c) + 10) if a > 0 else min(res, dfs(bamboo + 1, a + L[bamboo], b, c))
		res = min(res, dfs(bamboo + 1, a, b + L[bamboo], c) + 10) if b > 0 else min(res, dfs(bamboo + 1, a, b + L[bamboo], c))
		res = min(res, dfs(bamboo + 1, a, b, c + L[bamboo]) + 10) if c > 0 else min(res, dfs(bamboo + 1, a, b, c + L[bamboo]))
		res = min(res, dfs(bamboo + 1, a, b, c))
		return res

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



def __starting_point():
	main()
__starting_point()

import sys,math,collections,itertools
input = sys.stdin.readline

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

use_list = list(itertools.product(list(range(4)),repeat = N))
point = float('inf')

for i in range(len(use_list)):
    ABC = [0]*3
    count = [0]*3
    if (0 not in use_list[i]) or(1 not in use_list[i]) or (2 not in use_list[i]):
        continue
    for j in range(len(use_list[i])):
        if use_list[i][j] != 3:
            ABC[use_list[i][j]] += l[j]
            count[use_list[i][j]] += 1
    p = (sum(count)-len(count))*10+abs(ABC[0]-A)+abs(ABC[1]-B)+abs(ABC[2]-C)
    point = min(point,p)   
print(point)


n,a,b,c=map(int,input().split())
l = []
for i in range(n):
  l.append(int(input()))
m = [a,b,c]
ans = 4000
for i in range(4**n):
  p = [0]*n
  k = i
  for j in range(n):
    p[j] = k % 4
    k //= 4
  cost = [-1,-1,-1]
  q = [[] for _ in range(4)]
  for j in range(n):
    q[p[j]].append(l[j])
  for j in range(3):
    if len(q[j+1]) != 0:
      cost[j] = 10 * (len(q[j+1]) - 1) + abs(sum(q[j+1])-m[j])
  if cost[0] != -1 and cost[1] != -1 and cost[2] != -1:
    ans = min(ans, cost[0] + cost[1] + cost[2])
print(ans)

import itertools

n, a, b, c = map(int, input().split())
l = []
for i in range(n):
    l.append(int(input()))
mp = float("inf")
for i in itertools.product([0,1,2,3], repeat = n):
    if 0 not in i or 1 not in i or 2 not in i:
        continue
    la, lb, lc = 0, 0, 0
    temp = 0
    for j in range(3):
        temp += (i.count(j) - 1) * 10
    for j in range(n):
        if i[j] == 0:
            la += l[j]
        elif i[j] == 1:
            lb += l[j]
        elif i[j] == 2:
            lc += l[j]
    for j, k in [[la, a], [lb, b], [lc, c]]:
        temp += abs(j - k)
    mp = min(mp, temp)
print(mp)

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

l = []
for i in range(N):
    l.append(int(input()))

def dfs(i, a, b, c):
    if i == N:
        if min(a,b,c) == 0:
            return float("INF")
        else:
            return abs(a-A) + abs(b-B) + abs(c-C)
    else:
        ans0 = dfs(i+1, a, b, c) #棒iを使わないパターン
        ans1 = dfs(i+1, a+l[i], b, c) + (10 if a!=0 else 0)
        ans2 = dfs(i+1, a, b+l[i], c) + (10 if b!=0 else 0)
        ans3 = dfs(i+1, a, b, c+l[i]) + (10 if c!=0 else 0)
    return min(ans0, ans1, ans2, ans3)

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


N, A, B, C = map(int, input().split())
L = [0]*N
for i in range(N):
    L[i] = int(input())
INF = 10 ** 9


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

    return min(no_pattern, a_pattern, b_pattern, c_pattern)


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

n,a,b,c, = map(int,input().split())
l = list(int(input()) for i in range(n))
ans = 10 ** 6
for i in range(4 ** n):
    m = i
    j = 0
    x,xp,y,yp,z,zp = 0,0,0,0,0,0
    while m > 0:
        p = m % 4
        if p == 1:
            x += l[j]
            xp += 1
        elif p == 2:
            y += l[j]
            yp += 1
        elif p == 3:
            z += l[j]
            zp += 1
        else:
            pass
        m = m // 4
        j += 1
    if xp != 0 and yp != 0 and zp != 0:
        t = abs(a-x) + abs(b-y) + abs(c-z) + ((xp-1)*10) + ((yp-1)*10) + ((zp-1)*10)
        ans = min(ans,t)
print(ans)

#全探索をA,B,C一度で分けた
# RE 1   ac 19

# 初期入力
import copy
from itertools import combinations
import sys
input = sys.stdin.readline  #文字列では使わない
N,A,B,C = (int(i) for i in input().split())
l =[0]*N
for i in range(N):
    l[i] = int(input())

# A,B,Cどの竹を選ぶかcombination
mp=[]
for na in range(1,N-1):
    for ja in combinations(l,na):

        l_b =copy.copy(l)
        for i2 in ja:
            if i2 in l_b:
                l_b.remove(i2)
        for nb in range(1,N):
            for jb in combinations(l_b ,nb):

                l_c =copy.copy(l_b)
                for i3 in jb:
                    if i3 in l_c:
                        l_c.remove(i3)
                for nc in range(1,N+1):
                    for jc in combinations(l_c ,nc):
                        
                        # MPの消費量＝（求める長さー今回選んだ竹の長さ合計）+10*（合成魔法の回数)
                        AA =abs(A-sum(ja)) +10*(na-1)
                        BB =abs(B-sum(jb)) +10*(nb-1)
                        CC =abs(C-sum(jc)) +10*(nc-1)
                        mp.append(AA +BB +CC)


print(min(mp))

def B10N(X,B):
    if X//B!=0: return B10N(X//B,B)+str(X%B)
    return str(X%B)

N,A,B,C = (int(X) for X in input().split())
Li = [int(input()) for X in range(0,N)]
CostM = pow(10,9)
for T in range(0,pow(4,N)):
    Cho = list(B10N(T,4).zfill(N))
    if Cho.count('1')>0 and Cho.count('2')>0 and Cho.count('3')>0:
        Cost = 0
        ALi = [Li[X] for X,Y in enumerate(Cho) if Y=='1']
        BLi = [Li[X] for X,Y in enumerate(Cho) if Y=='2']
        CLi = [Li[X] for X,Y in enumerate(Cho) if Y=='3']
        SyC = (len(ALi)+len(BLi)+len(CLi)-3)*10
        LeC = abs(sum(ALi)-A)+abs(sum(BLi)-B)+abs(sum(CLi)-C)
        if SyC+LeC<CostM: CostM = SyC+LeC
print(CostM)