CodeEff/ECCO huggingface dataset:
# Original solution
def main():
    #入力をとる
    n,a,b,c = list(map(int,input().split()))
    moto = [int(eval(input())) for i in range(n)]

    take = []
    take.append(a)
    take.append(b)
    take.append(c)

    mp = 10000000000
    pt= []
    #全探索
    for i in range(2**(2*n)):
        pt = []
        for j in range(n):
            if (i >> j*2)&1:
                if (i >> j*2+1)&1:
                    pt.append(3)
                else:
                    pt.append(1)
            else:
                if (i >> j*2+1)&1:
                    pt.append(2)
                else:
                    pt.append(0)       

        #keisan
        mp_tmp = 0
        all_used = True
        for k in range(3):
            if pt.count(k) == 0:
                all_used = False
                break

            sum_tmp = 0
            mp_tmp += (pt.count(k) - 1)*10
            for l in range(n):
                if pt[l] == k:
                    sum_tmp += moto[l]
            
            mp_tmp += abs(sum_tmp-take[k])

        if all_used == True:
            mp = min(mp_tmp, mp)
    print(mp)

main()

# Optimized solution
minmp = 10000000
def dfs(depth, pt):

    if depth==n:
        mp_tmp = 0
        all_used = True
        for k in range(3):
            if pt.count(k) == 0:
                all_used = False
                break

            sum_tmp = 0
            mp_tmp += (pt.count(k) - 1)*10
            for l in range(n):
                if pt[l] == k:
                    sum_tmp += moto[l]
            
            mp_tmp += abs(sum_tmp-take[k])

        if all_used == True:
            global minmp
            minmp = min(minmp,mp_tmp)
            return
        else:
            return

    for i in range(4):
        pt[depth] = i
        dfs(depth+1, pt)

    return

#入力をとる
n,a,b,c = list(map(int,input().split()))
moto = [int(eval(input())) for i in range(n)]


take = []
take.append(a)
take.append(b)
take.append(c)

pt  = [3]*n
for i in range(n):
    dfs(i,pt)

print(minmp)
# Original solution

N,A,B,C = list(map(int, input().split()))
bamboos = [int(eval(input())) for _ in range(N)]
#print("---", bamboos)
ans = float("inf")
def solve(lst, idx):
    global ans
    if idx == N:
        #print("qqqqq")
        for i in range(3):
            if len(lst[i]) == 0:
                return

        
        pa = 10 * (len(lst[0])-1) + abs(A - sum(lst[0]))
        pb = 10 * (len(lst[1])-1) + abs(B - sum(lst[1]))
        pc = 10 * (len(lst[2])-1) + abs(C - sum(lst[2]))
        #print(pa, pb, pc, lst)
        ans = min(ans, pa + pb + pc)
        #print("aaaaaaa")
        return

    
    for i in range(4):
        nxt_lst = [lst[0][:], lst[1][:], lst[2][:], lst[3][:]]
        nxt_lst[i].append(bamboos[idx])
        #print(lst, nxt_lst)
        
        solve(nxt_lst, idx+1)

empty_lst =  [[], [], [], []]   
solve(empty_lst, 0)
print(ans)

# Optimized solution

N,A,B,C = list(map(int, input().split()))
bamboos = [int(eval(input())) for _ in range(N)]
#print("---", bamboos)
INF = float("inf")
ans = INF
def solve(idx, cnt_merge, a, b, c):

    if idx == N:
        if min(a,b,c) > 0:
            return abs(A - a) + abs(B - b) + abs(C - c) + 10 * (cnt_merge-3)
        else:
            return INF

    pa = solve(idx+1, cnt_merge+1, a+bamboos[idx], b, c)
    pb = solve(idx+1, cnt_merge+1, a, b+bamboos[idx], c)
    pc = solve(idx+1, cnt_merge+1, a, b, c+bamboos[idx])
    pn = solve(idx+1, cnt_merge, a, b, c)
    return min(pa, pb, pc, pn)


print((solve(0,0,0,0,0)))
# Original solution
N, A, B, C = list(map(int, input().split()))

bamboos = []
for _ in range(N):
    l = int(eval(input()))
    bamboos.append(l)
    
ABC = [A, B, C]

import itertools
import sys

ans = sys.maxsize
executed = set()
for i in range(3, N+1):
    for bamboos_rearranged in itertools.permutations(bamboos, i):
        execute = ','.join(map(str,bamboos_rearranged))
        if execute in executed:
            continue
        else:
            executed.add(execute)
        #print(bamboos_rearranged)
        for j in range(1, len(bamboos_rearranged)):
            for k in range(j+1, len(bamboos_rearranged)):
                bamboos_abc = (bamboos_rearranged[:j], bamboos_rearranged[j:k], bamboos_rearranged[k:])
                cost = 0
                flag = True
                for n, b in enumerate(bamboos_abc):
                    cost += (len(b) - 1) * 10
                    cost += abs(ABC[n] - sum(b))
                    if cost >= ans:
                        flag = False
                        break
                if flag == True:
                    ans = min(ans, cost)
print(ans)
        
    

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

bamboos = []
for _ in range(N):
    l = int(eval(input()))
    bamboos.append(l)
    
import copy

def dfs(i, bs):
    if i == len(bamboos):
        #print(bs)
        if not bs['A'] or not bs['B'] or not bs['C']:
            return []
        return [bs]
    ret = []
    tmp = copy.deepcopy(bs)
    tmp['A'].append(bamboos[i])
    ret.extend(dfs(i+1, tmp))
    tmp = copy.deepcopy(bs)
    tmp['B'].append(bamboos[i])
    ret.extend(dfs(i+1, tmp))
    tmp = copy.deepcopy(bs)
    tmp['C'].append(bamboos[i])
    ret.extend(dfs(i+1, tmp))
    tmp = copy.deepcopy(bs)
    tmp['D'].append(bamboos[i])
    ret.extend(dfs(i+1, tmp))
    
    return ret

ABC = {'A': A, 'B': B, 'C': C}
bs_comb = dfs(0, {'A':[],'B':[],'C':[],'D':[]})

import sys
ans = sys.maxsize
for bs in bs_comb:
    cost = 0
    for abc in ['A', 'B', 'C']:
        cost += (len(bs[abc]) - 1) * 10
        cost += abs(sum(bs[abc]) - ABC[abc])
    ans = min(ans, cost)
print(ans)
# Original solution
import itertools

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

for n in range(1, N + 1):
    P.extend(itertools.combinations([n for n in range(N)], n))

add_len = {s: sum(L[i] for i in s) for s in P}


def cost(v, s):
    return 10 * (len(s) - 1) + abs(v - add_len[s])


res = 2 << 30
for a in P:
    cost_a = cost(A, a)
    if res < cost_a:
        continue

    for b in P:
        cost_b = cost(B, b)
        if res < cost_b:
            continue

        if len(set(a) & set(b)):
            continue

        for c in P:
            cost_c = cost(C, c)
            if res < cost_c:
                continue

            if len(set(a) & set(c)) or len(set(b) & set(c)):
                continue
            res = min(res, cost_a + cost_b + cost_c)

print(res)


# Optimized solution
import itertools

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

for n in range(1, N + 1):
    P.extend(itertools.combinations([n for n in range(N)], n))

add_len = {s: sum(L[i] for i in s) for s in P}


def cost(v, s):
    return 10 * (len(s) - 1) + abs(v - add_len[s])


res = 2 << 30
for a in P:
    cost_a = cost(A, a)
    if res < cost_a:
        continue

    for b in P:
        cost_b = cost(B, b)
        if res < cost_b:
            continue

        set_a = set(a)
        set_b = set(b)
        if len(set_a & set_b):
            continue

        for c in P:
            cost_c = cost(C, c)
            if res < cost_c:
                continue

            set_c = set(c)
            if len(set_a & set_c) or len(set_b & set_c):
                continue
            res = min(res, cost_a + cost_b + cost_c)

print(res)
# Original solution
from itertools import permutations

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

    # full search
    ans = 10**9
    for perm in permutations(l):
        cost = -30
        for i in range(1, n-1):
            cost1 = cost + 10 * len(perm[:i]) + abs(a - sum(perm[:i]))
            for j in range(i+1, n):
                cost2 = cost1 + 10 * len(perm[i:j]) + abs(b - sum(perm[i:j]))
                for k in range(j+1, n+1):
                    cost3 = cost2 + 10 * len(perm[j:k]) + abs(c - sum(perm[j:k]))
                    if cost3 < ans:
                        ans = cost3

    print(ans)

main()

# Optimized solution
from itertools import product
from sys import stdin
input = stdin.buffer.readline

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

    ans = 10**9
    for prod in product([0, 1, 2, 3], repeat=n):
        cost = 10 * (n-3)
        lengths = [0, 0, 0]
        for i, x in enumerate(prod):
            if x < 3:
                lengths[x] += l[i]
            else:
                cost -= 10

        for i in lengths:
            if i == 0:
                break

        else:
            for i, x in enumerate(abc):
                cost += abs(x - lengths[i])
            if cost < ans:
                ans = cost

    print(ans)

main()
# Original solution
n,a,b,c = list(map(int,input().split()))
L = [int(eval(input())) for i in range(n)]
MP = []
for i in range(4**n):
    i_bit = bin(i)[2:].zfill(2*n)
    co_a = 0
    co_b = 0
    co_c = 0
    p_a = 0
    p_b = 0
    p_c = 0
    for j in range(n):
        if i_bit[-1-2*j:-3-2*j:-1] == '00':
            co_a += L[j]
            p_a += 1
        elif i_bit[-1-2*j:-3-2*j:-1] == '01':
            co_b += L[j]
            p_b += 1
        elif i_bit[-1-2*j:-3-2*j:-1] == '10':
            co_c += L[j]
            p_c += 1
        else:
            continue
    if co_a*co_b*co_c!=0 and p_a<=a and p_b<=b and p_c<=c:
        MP += [10*(p_a+p_b+p_c-3)+abs(a-co_a)+abs(b-co_b)+abs(c-co_c)]
print((min(MP)))

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

minmp = 10**18

for i in range(4**N):
    mp = 0
    a = []
    b = []
    c = []
    d = []
    
    for j in range(N):
        if i>>(2*j) & 1:
            if i>>(2*j+1) & 1:
                a.append(j)
            else:
                b.append(j)
        else:
            if i>>(2*j+1) & 1:
                c.append(j)
            else:
                d.append(j)
                
    if not a or not b or not c:
        continue
        
    mp += (len(a)-1)*10
    mp += abs(A-sum([L[j] for j in a]))
    mp += (len(b)-1)*10
    mp += abs(B-sum([L[j] for j in b]))
    mp += (len(c)-1)*10
    mp += abs(C-sum([L[j] for j in c]))
    minmp = min(mp,minmp)

print(minmp)
# Original solution
# ABC119C - Synthetic Kadomatsu
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for i in range(N)]

INF = float('inf')

def dfs(cursor=0, a=0, b=0, c=0):  # cursor:カーソル a,b,c:現在の竹の長さ
    if cursor == N:  # cursorが最後まで行ったら終了する。
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    # abs(a - A) + abs(b - B) + abs(c - C) - 30でなぜ 30を減じているのかというと、
    # dfs(0,0,0,0)で始まる以上、最初に選ばれるa,b,cを決定する際にもコストが 10増加してしまうからである。
    # また、全探索を行う中で、a,b,cの初期値が 0,0,0である以上、a,b,cのどれかが 0のまま終了する場合が存在する。
    # この場合はa,b,cに竹が対応してないと言えるため、解にはならない。
    # そこで三項演算子を利用して、その場合についてコストをINFとしている

    # 以下は4^Nで展開される再起処理となる。
    # カーソルの当たっている竹に対して、(A or B or Cに合成する) or (合成しない)の場合に分ける
    no_compound_pattern = dfs(cursor + 1, a, b, c)
    compound_a_pattern = dfs(cursor + 1, a + L[cursor], b, c) + 10
    compound_b_pattern = dfs(cursor + 1, a, b + L[cursor], c) + 10
    compound_c_pattern = dfs(cursor + 1, a, b, c + L[cursor]) + 10

    # 結果的に以下の値が返るのはそれぞれのパターンのコストが決定されてからなので
    # 以下のコードは最終的なコストの最小値
    return min(
        no_compound_pattern, compound_a_pattern, compound_b_pattern, compound_c_pattern
    )


print((dfs()))

# Optimized solution
n, *goals = list(map(int, input().split()))
bamboos = list(map(int, [input().rstrip() for _ in range(n)]))


def get_best(li, goal):
    bam_mp_lis = {0: (-10, tuple())}
    li.sort()
    for i, v in enumerate(li):
        tmp = bam_mp_lis.copy()
        for bam, (mp, lis) in list(tmp.items()):
            b0 = bam + v
            m0 = mp + 10
            l0 = lis + (i,)
            if b0 not in bam_mp_lis or m0 < bam_mp_lis[b0][0]:
                bam_mp_lis[b0] = (m0, l0)
    del bam_mp_lis[0]
    best = 10 ** 9
    for bam, (mp, lis) in list(bam_mp_lis.items()):
        cost = mp + abs(goal - bam)
        if cost < best:
            best = cost
            beslis = lis
    return best, beslis


ans = 10 ** 9
from itertools import permutations

for junjo in permutations(goals):
    tmp = 0
    bambooo = bamboos.copy()
    for ju in junjo:
        if len(bambooo) == 0:
            tmp = 10 ** 9
            break
        be, beli = get_best(bambooo, ju)
        beli = sorted(beli, reverse=True)
        for beli0 in beli:
            del bambooo[beli0]
        tmp += be
    if tmp < ans:
        ans = tmp

print(ans)
# Original solution
#18:51
n,A,B,C = list(map(int,input().split()))
D = [A,B,C]
l = []
for _ in range(n):
  l.append(int(eval(input())))
l.sort(reverse=True)
def nex(time):
  for i in range(n-1,-1,-1):
    if time[i] < 3:
      time[i] += 1
      break
    else:
      time[i] = 0
  else:
    time = 'over'
  return time
#print(nex([0,0,0,0]),nex([0,3,3,3]),nex([3,3,3,3]))
can = []
time = [0 for _ in range(n)]
while time != 'over':
  ans = (n-3) * 10
  d = [0,0,0]
  for i in range(n):
    t = time[i]
    if t == 3:
      ans -= 10
    else:
      d[t] += l[i]
  if all(d[k] != 0 for k in range(3)):
    for k in range(3):
      ans += abs(D[k] - d[k])
    can.append([ans,d])
  time = nex(time)
print((min(can,key=lambda x:x[0])[0]))

# Optimized solution
n,A,B,C = list(map(int,input().split()))
D = [A,B,C]
def nex(time):
  for i in range(n):
    if time[i] < 3:
      time[i] += 1
      break
    else:
      time[i] = 0
  else:
    time = 'over'
  return time
boo = []
for _ in range(n):
  boo.append(int(eval(input())))
can = []
time = [0 for _ in range(n)]
while time != 'over':
  d = [0,0,0]
  tmp = (n-3) * 10
  for i in range(n):
    if time[i] < 3:
      d[time[i]] += boo[i]
    else:
      tmp -= 10
  for k in range(3):
    tmp += abs(D[k] - d[k])
  if d[0] * d[1] * d[2] != 0:
    can.append(tmp)
  time = nex(time)
print((min(can)))
# Original solution
n,a,b,c = list(map(int,input().split()))
la = [a,b,c]
lt = [int(eval(input())) for i in range(n)]

import itertools as it
ans = 3000
for p in it.product(list(range(4)),repeat=n):
  ll = [0]*4
  lc = [0]*4
  for i in range(n):
    ll[p[i]] += lt[i]
    lc[p[i]] += 1
  if lc[0]*lc[1]*lc[2] > 0:
    mp = 10*(sum(lc[:3])-3) + sum(abs(ll[i]-la[i]) for i in range(3))
    ans = min(ans, mp)
print(ans)

# Optimized solution
import sys
input = sys.stdin.readline

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

import itertools as it
ans = 3000
for p in it.product(list(range(4)),repeat=n):
  ll = [0]*4
  lc = [0]*4
  for i in range(n):
    ll[p[i]] += lt[i]
    lc[p[i]] += 1
  if lc[0]*lc[1]*lc[2] > 0:
    mp = 10*(sum(lc[:3])-3) + sum(abs(ll[i]-la[i]) for i in range(3))
    ans = min(ans, mp)
print(ans)
# Original solution
def change_base(n, base):
    q = n // base
    r = n % base
    if q == 0:
        return str(r)
    return change_base(q, base) + str(r)


N, A, B, C = list(map(int, input().split()))
target = [A, B, C]
l = [int(eval(input())) for _ in range(N)]
ans = float('inf')
for n in range(4**N):
    bit = change_base(n, 4)
    bit = '0'*(N-len(bit)) + bit
    start = [0] * 3
    mp = 0
    for i in range(N):
        for j in range(3):
            if bit[i] == str(j):
                if start[j] > 0:
                    mp += 10
                start[j] += l[i]
    if any(s == 0 for s in start):
        continue
    for j in range(3):
        mp += abs(target[j]-start[j])
    ans = min(ans, mp)
print(ans)


# Optimized solution
def dfs(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 float('inf')
    mx = dfs(i+1, a, b, c)
    ma = dfs(i+1, a+l[i], b, c) + 10
    mb = dfs(i+1, a, b+l[i], c) + 10
    mc = dfs(i+1, a, b, c+l[i]) + 10
    return min(mx, ma, mb, mc)


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

def search(arr,arr2,cost,flag):
  global mincost
  if cost>mincost:
    return 0
  if flag==0:
    if len(arr2)==0:
      ans.add(cost)
      if mincost>cost:
        mincost=cost
      return 0
    for i in range(len(arr)):
      search(arr[:i]+arr[i+1:],arr2[1:],cost+abs(arr2[0]-arr[i]),0)
  else:
    if len(arr)>=len(arr2)+1:
      for i in range(len(arr)):
        for j in range(i+1,len(arr)):
          search(arr[:i]+arr[i+1:j]+arr[j+1:]+[arr[i]+arr[j]],arr2,cost+10,0)
          search(arr[:i]+arr[i+1:j]+arr[j+1:]+[arr[i]+arr[j]],arr2,cost+10,1)

n,a,b,c=list(map(int,input().split()))
arr=[int(eval(input())) for _ in range(n)]
arr2=[a,b,c]
ans=set()
mincost=10**9

search(arr,arr2,0,0)
search(arr,arr2,0,1)

ans=sorted(list(ans))
print((ans[0]))

# Optimized solution
import collections
from copy import deepcopy

n,a,b,c=list(map(int,input().split()))
arr=[int(eval(input())) for _ in range(n)]
l=collections.deque()
l.append([[],[],[]])
cnt=0

while 1:
  if cnt==n:
    break
  base=l.popleft()
  if len(base[0])==0 and len(base[1])==0 and len(base[2])==0:
    l.append([[arr[cnt]],[],[]])
    l.append([[],[arr[cnt]],[]])
    l.append([[],[],[arr[cnt]]])
    l.append([[],[],[]])
    cnt+=1
  else:
    tmp1=deepcopy(base)
    tmp1[0].append(arr[cnt])
    l.append(tmp1)
    tmp2=deepcopy(base)
    tmp2[1].append(arr[cnt])
    l.append(tmp2)
    tmp3=deepcopy(base)
    tmp3[2].append(arr[cnt])
    l.append(tmp3)
    tmp4=deepcopy(base)
    l.append(tmp4)

mincost=10**9
for bl in l:
  if len(bl[0])==0 or len(bl[1])==0 or len(bl[2])==0:
    continue
  else:
    tmpcost=abs(sum(bl[0])-a)+abs(sum(bl[1])-b)+abs(sum(bl[2])-c)+10*(len(bl[0])-1+len(bl[1])-1+len(bl[2])-1)
    if mincost>tmpcost:
      mincost=tmpcost
print(mincost)
# Original solution
import sys
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: list(map(int, readline().split()))
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, A, B, C = in_nn()
    l = list(map(int, read().rstrip().split()))

    comb = list(itertools.product(list(range(4)), repeat=N))
    abc_p = list(itertools.permutations([A, B, C], 3))

    ans = 10**9 + 7
    for abc in abc_p:
        for c in comb:
            if (0 in c) and (1 in c) and (2 in c):
                t = [0] * 3
                m = [-10] * 3
                for i in range(N):
                    if c[i] == 3:
                        continue
                    t[c[i]] += l[i]
                    m[c[i]] += 10

                for i in range(3):
                    m[i] += abs(t[i] - abc[i])

                ans = min(ans, sum(m))

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
import sys
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: list(map(int, readline().split()))
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, A, B, C = in_nn()
    l = list(map(int, read().rstrip().split()))

    comb = list(itertools.product(list(range(4)), repeat=N))
    ans = 10**9 + 7

    for c in comb:
        if (0 in c) and (1 in c) and (2 in c):
            t = [0] * 3
            m = [-10] * 3
            for i in range(N):
                if c[i] == 3:
                    continue
                t[c[i]] += l[i]
                m[c[i]] += 10

            m[0] += abs(t[0] - A)
            m[1] += abs(t[1] - B)
            m[2] += abs(t[2] - C)

            ans = min(ans, sum(m))

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
N, A, B, C = list(map(int, input().split(" ")))
l = [int(eval(input())) for i in range(N)]
INF = 10 ** 9
def dfs(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
    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 = [0]*N
for i in range(N):
    l[i] = int(eval(input()))
def dfs(i,a,b,c):
    if i == N:
        if a==0 or b==0 or c==0:
            return 100000
        else:
            return abs(A-a)+abs(B-b)+abs(C-c)-30
    else:
         return min(dfs(i+1,a+l[i],b,c)+10, dfs(i+1,a,b+l[i],c)+10, dfs(i+1,a,b,c+l[i])+10, dfs(i+1,a,b,c))

print((dfs(0,0,0,0)))
# Original solution
from collections import deque

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

p = deque()
p.append([-1] * len(L))
while p:
    stats = p.pop()
    stats = list(stats)
    a, b, c = 0, 0, 0
    MP = 0
    cntA = 0; cntB = 0; cntC = 0
    for i in range(N):
        if stats[i] == 1:
            a += L[i]
            cntA += 1
        elif stats[i] == 2:
            b += L[i]
            cntB += 1
        elif stats[i] == 3:
            c += L[i]
            cntC += 1

    if cntA >= 1 and cntB >= 1 and cntC >= 1:
        MP += abs(A - a) + abs(B - b) + abs(C - c) + 10 * (cntA+cntB+cntC-3)
        minMP = min(minMP, MP)

    if not -1 in stats:
        continue
    j = stats.index(-1)
    for k in range(4):
        stats[j] = k
        newStats = tuple(stats)
        p.append(newStats)

print(minMP)


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

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

    no_compound = dfs(cursor+1, a, b, c)
    A_compound = dfs(cursor+1, a+L[cursor], b, c) + 10
    B_compound = dfs(cursor+1, a, b+L[cursor], c) + 10
    C_compound = dfs(cursor+1, a, b, c+L[cursor]) + 10
    return min(no_compound, A_compound, B_compound, C_compound)

print((dfs()))
# Original solution
n, *abc = [int(x) for x in input().split()]
l = [int(eval(input())) for i in range(n)]
A = 0; B = 1; C = 2;

minmp = 10 ** 9
for k in range(2 ** (2 * n)):
    mat = [[], [], [], []]  # mat[0]:= Aの材料, mat[1]:=Bの材料, mat[2]:=Cの材料
    # for i = 0, ..., N-1
    # kの 2*i & 2*i+1ビット目が 0b00: l[i]はAに使う
    #     ↑lsbから             0b01: l[i]はBに使う
    #                         0b10: l[i]はCに使う
    #                         0b11: l[i]は使わない
    for i in range(n):
        mat[(k >> 2 * i) & (0b11)].append(l[i])

    if len(mat[0]) == 0 or len(mat[1]) == 0 or len(mat[2]) == 0:
        continue
        
    mp = 0
    for j in range(3):
        mp += 10 * (len(mat[j]) - 1)
        mp += 1 * abs(abc[j] - sum(mat[j]))

    minmp = min(minmp, mp)

print(minmp)

# Optimized solution
n, *abc = [int(x) for x in input().split()]
l = [int(eval(input())) for i in range(n)]
A = 0; B = 1; C = 2;

minmp = 10 ** 9
for k in range(2 ** (2 * n)):
    mat = [[], [], [], []]  # mat[0]:= Aの材料, mat[1]:=Bの材料, mat[2]:=Cの材料
    # for i = 0, ..., N-1
    # kの 2*i & 2*i+1ビット目が 0b00: l[i]はAに使う
    #     ↑lsbから             0b01: l[i]はBに使う
    #                         0b10: l[i]はCに使う
    #                         0b11: l[i]は使わない
    for i in range(n):
        mat[k & (0b11)].append(l[i])
        k >>= 2

    if len(mat[0]) == 0 or len(mat[1]) == 0 or len(mat[2]) == 0:
        continue

    mp = 0
    for j in range(3):
        mp += 10 * (len(mat[j]) - 1)
        mp += 1 * abs(abc[j] - sum(mat[j]))

    minmp = min(minmp, mp)

print(minmp)