CodeEff/ECCO huggingface dataset:
# Original solution
# coding:utf-8

import sys
import itertools

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())


n, a, b, c = LI()
A = [a, b, c]
K = [II() for _ in range(n)]

ans = INF
for x in itertools.product([0, 1, 2, 3], repeat=n):
    s = set(x)
    if 0 not in s or 1 not in s or 2 not in s:
        continue
    T = [0] * 3
    cnt = 0
    for i, n in enumerate(x):
        if n == 3:
            continue
        if T[n]:
            cnt += 1
        T[n] += K[i]

    # print(T, cnt)
    tmp = cnt * 10
    for i in range(3):
        tmp += abs(T[i] - A[i])

    ans = min(ans, tmp)

print(ans)


# Optimized solution
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())


n, a, b, c = LI()
A = [a, b, c]
K = [II() for _ in range(n)]


def DFS(cur, x, y, z):
    if cur == n:
        return abs(x - a) + abs(y - b) + abs(z - c) - 30 if min(x, y, z) > 0 else INF
    ret0 = DFS(cur + 1, x, y, z)
    ret1 = DFS(cur + 1, x + K[cur], y, z) + 10
    ret2 = DFS(cur + 1, x, y + K[cur], z) + 10
    ret3 = DFS(cur + 1, x, y, z + K[cur]) + 10
    return min(ret0, ret1, ret2, ret3)


print((DFS(0, 0, 0, 0)))
# Original solution
N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for i in range(N)]
def dfs(d, a, b, c):
  if d == N:
    res = abs(a - A) + abs(b - B) + abs(c - C) - 30
    return 1e9 if min(a, b, c) == 0 else res
  ret = [0] * 4
  ret[0] = dfs(d + 1, a, b, c)
  ret[1] = dfs(d + 1, a + l[d], b, c) + 10
  ret[2] = dfs(d + 1, a, b + l[d], c) + 10
  ret[3] = dfs(d + 1, a, b, c + l[d]) + 10
  return min(ret)
print((dfs(0, 0, 0, 0)))


# Optimized solution
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
def 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)))
# Original solution
import itertools 
def diff(a,b,c):
    return abs(A-a)+abs(B-b)+abs(C-c)
    
N,A,B,C,*l=list(map(int,open(0).read().split()))
_min=10**6
for i in itertools.product([0,1,2,3],repeat=N):
    cnt=0
    abc=[0,0,0]
    for j in range(N):
        if i[j] !=3:
            abc[i[j]]+=l[j]
            cnt+=1
    if 0 in abc:
        continue
    _min=min(_min,10*cnt-30+diff(abc[0],abc[1],abc[2]))
print(_min)    
    

# Optimized solution
def dfs(cnt,a,b,c):
    if cnt == N:
        _sum = abs(A-a) + abs(B-b) + abs(C-c) - 30
        return _sum if min(a,b,c) > 0 else 10**9
    ret0 = dfs(cnt+1, a, b, c)
    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
    return min(ret0,ret1,ret2,ret3) 
    
N,A,B,C,*l = list(map(int,open(0).read().split()))
print((dfs(0,0,0,0)))
# Original solution
from itertools import product
n,*B=list(map(int,input().split()))
A=[int(eval(input())) for i in range(n)]
s=10**9
for P in product([0,1,2,3],repeat=n):
  if {0,1,2}<=set(P):
    m=[0,0,0]
    for x,y in zip(P,A):
      if x!=3:
        m[x]+=y
    t=sum(abs(m-y) for m,y in zip(m,B))
    l=sum(1 for j in P if j!=3)-3
    s=min(s,t+l*10)
print(s)

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

for i in product(list(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)))
# Original solution
def dfs(depth):
    if depth == N:
        ans.append(cal(v))
        return
    for i in range(4):
        v[depth] = i
        dfs(depth+1) 

def cal(v):
    tmp = [0] * 3 
    for i in range(N):
        if v[i] == 0:
            tmp[0] += l[i]
        elif v[i] == 1:
            tmp[1] += l[i]
        elif v[i] == 2:
            tmp[2] += l[i]
    cnt = 0
    if v.count(0) > 1:
        cnt += v.count(0) - 1
    if v.count(1) > 1:
        cnt += v.count(1) - 1
    if v.count(2) > 1:
        cnt += v.count(2) - 1

    if v.count(0) == 0 or v.count(1) == 0 or v.count(2) == 0:
        return float('inf')
    diff = cnt * 10
    for i in range(3):
        diff += abs(A[i]-tmp[i])
    
    return diff
        
    
    

N, *A= list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
v = [-1] * N

ans = []

dfs(0)
print((min(ans)))

# Optimized solution
from itertools import product

def main():
    N, A, B, C = list(map(int, input().split()))
    L = list(int(eval(input())) for _ in range(N))
    ans = 0
    # A => 0
    # B => 1
    # C => 2
    ans = float('inf')
    for item in product(list(range(4)), repeat=N):
        length_A = 0
        cnt_A = 0
        score_A = 0
        length_B = 0
        cnt_B = 0
        score_B = 0
        length_C = 0
        cnt_C = 0
        score_C = 0
        for i,j in enumerate(item):
            if j == 0:
                length_A += L[i]
                cnt_A += 1
            if j == 1:
                length_B += L[i]
                cnt_B += 1
            if j == 2:
                length_C += L[i]
                cnt_C += 1
        if cnt_A == 0 or cnt_B == 0 or cnt_C == 0:
            continue
        score_A += abs(A - length_A) + 10 * (cnt_A - 1)
        score_B += abs(B - length_B) + 10 * (cnt_B - 1)
        score_C += abs(C - length_C) + 10 * (cnt_C - 1)
        ans = min(ans, score_A + score_B + score_C)
    print(ans)

if __name__ == "__main__":
    main()
# Original solution
def dfs(i, A, B, C):
    global ans
    if i == n:
        if A and B and C:
            s = 0
            ABC = [A, B, C]
            for i in range(3):
                s += (len(ABC[i]) - 1) * 10 + abs(sum(ABC[i]) - abc[i])
            ans = min(ans, s)
    else:
        dfs(i + 1, A + [l[i]], B, C)
        dfs(i + 1, A, B + [l[i]], C)
        dfs(i + 1, A, B, C + [l[i]])
        dfs(i + 1, A, B, C)

n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for i in range(n)]
abc = [a, b, c]
ans = float("inf")
dfs(0, [], [], [])
print(ans)

# Optimized solution
def dfs(i, A, B, C):
    global ans
    if i == n:
        if A and B and C:
            ans = min(ans, abs(a - sum(A)) + abs(b - sum(B)) + abs(c - sum(C)) + (len(A) + len(B) + len(C) - 3) * 10)
    else:
        # a の肉焼き器に乗せるか、 b の肉焼き器に乗せるか
        dfs(i + 1, A, B, C)
        dfs(i + 1, A + [L[i]], B, C)
        dfs(i + 1, A, B + [L[i]], C)
        dfs(i + 1, A, B, C + [L[i]])

n, a, b, c = list(map(int, input().split()))
L = [int(eval(input())) for i in range(n)]
ans = float("inf")
dfs(0, [], [], [])
print(ans)
# Original solution
def dfs(i, A, B, C):
    global ans
    if i == n:
        if A and B and C:
            ans = min(ans, abs(a - sum(A)) + abs(b - sum(B)) + abs(c - sum(C)) + (len(A) + len(B) + len(C) - 3) * 10)
    else:
        dfs(i + 1, A, B, C)
        dfs(i + 1, A + [L[i]], B, C)
        dfs(i + 1, A, B + [L[i]], C)
        dfs(i + 1, A, B, C + [L[i]])

n, a, b, c = list(map(int, input().split()))
L = [int(eval(input())) for i in range(n)]
ans = float("inf")
dfs(0, [], [], [])
print(ans)

# Optimized solution
def dfs(i, a, b, c, plus):
    global ans

    if i == n:
        if a and b and c:
            mp = abs(a - A) + abs(b - B) + abs(c - C) + (plus - 3) * 10
            ans = min(ans, mp)

    else:
        dfs(i + 1, a, b, c, plus)
        dfs(i + 1, a + l[i], b, c, plus + 1)
        dfs(i + 1, a, b + l[i], c, plus + 1)
        dfs(i + 1, a, b, c + l[i], plus + 1)


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

ans = float("inf")

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

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

for i in range(n):
    t = int(eval(input()))
    take.append(t)

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 cal_cost(li, a):
    if li == []:
        return 10**12
    co = 0
    if len(li) == 1:
        co += abs(li[0] - a)
    else:
        co += abs(sum(li) - a)
        co += (len(li) - 1) * 10
    return co

min_cost = 10**12
for i in range(4**n):
    cost = 0
    num = Base_10_to_n(i, 4).zfill(n)
    for_A = []
    for_B = []
    for_C = []
    for j in range(n):
        if num[j] == '1':
            for_A.append(take[j])
        elif num[j] == '2':
            for_B.append(take[j])
        elif num[j] == '3':
            for_C.append(take[j])
    cost += cal_cost(for_A, a)
    cost += cal_cost(for_B, b)
    cost += cal_cost(for_C, c)
    if cost < min_cost:
        min_cost = cost

print(min_cost)


# Optimized solution
n, a, b, c = list(map(int, input().split()))
bamboos = []
for i in range(n):
    bamboo = int(eval(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)
# Original solution
import sys
input=sys.stdin.readline

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

Ans=10**9
for i in range(4**n):
    F=[[] for i in range(3)] #竹格納:[A,B,C]
    now=i
    for j in range(n):
        r=now%(4**(j+1))
        chk=r//(4**(j))
        if chk!=3:
            F[chk].append(L[j])
        now-=r    
    if F[0] and F[1] and F[2]: #竹が1本以上あるとき
        ans=0
        for k in range(3):
            f=F[k] #竹一覧
            Len=len(f)
            mp=10**9
            for l in range(1,2**Len):
                t=0
                cnt=0
                for q in range(Len):
                    if (l>>q)&1:
                        cnt+=1
                        t+=f[q]
                mp=min(abs(t-A[k])+10*(max(0,cnt-1)),mp)
            ans+=mp
        Ans=min(ans,Ans)
print(Ans)

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

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

ans=10**9
for i in range(4**n):
    F=[[] for i in range(3)] #竹格納:[A,B,C]
    now=i
    for j in range(n):
        r=now%(4**(j+1))
        chk=r//(4**(j))
        if chk!=3:
            F[chk].append(L[j])
        now-=r    
    if F[0] and F[1] and F[2]: #竹が1本以上あるとき
        mp=0
        for k in range(3):
            f=F[k]
            mp+=abs(sum(f)-A[k])+10*(max(0,len(f)-1))
        ans=min(mp,ans)
print(ans)
# Original solution
# -*- coding: utf-8 -*-
from itertools import product
def inpl(): return list(map(int, input().split()))

N, A, B, C = inpl()
L = [int(eval(input())) for _ in range(N)]

ans = 1e9

def calc(Q, D):
    S = sum(Q)
    res = 10*(len(Q)-1) + abs(D-S)
    return res


for X in product(list(range(4)), repeat=N):
    P = [[] for _ in range(4)]
    for i, x in enumerate(X):
        P[x].append(L[i])
    if min(list(map(len, P[1:]))) == 0:
        continue
    tmp = 0
    for Q, D in zip(P[1:], [A, B, C]):
        tmp += calc(Q, D)
    if tmp < ans:
        ans = min(tmp, ans)

print(ans)

# Optimized solution
# -*- coding: utf-8 -*-
from itertools import product
def inpl(): return list(map(int, input().split()))

N, A, B, C = inpl()
L = [int(eval(input())) for _ in range(N)]

ans = 1e9

for X in product(list(range(4)), repeat=N):
    P = [[] for _ in range(4)]
    for i, x in enumerate(X):
        P[x].append(L[i])

    if min(list(map(len, P[1:]))) == 0:
        continue

    tmp = 0
    for Q, D in zip(P[1:], [A, B, C]):
        tmp += 10*(len(Q)-1) + abs(D-sum(Q))
    if tmp < ans:
        ans = min(tmp, ans)

print(ans)
# Original solution
import itertools

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

cl = ('A', 'B', 'C', 'N')

result = 1e10
for pattern in itertools.product(*[cl]*n):
    wands = {'A': 0, 'B': 0, 'C': 0}
    point = 0
    for i, char in enumerate(pattern):
        if char != 'N':
            if wands[char] != 0:
                point += 10
            wands[char] += _l[i]
    if min(wands.values()) > 0:
        point += abs(wands['A'] - a) + abs(wands['B'] - b) + abs(wands['C'] - c)
        if point < result:
            result = point

print(result)


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

inf = 10**9


# DP
def f(i, _a, _b, _c):
    # A,B,Cにしようとしている枝の長さが現在_a,_b,_cのとき,i番目以降の材料を使って達成される点数の最小値
    if i == n:
        return abs(a - _a) + abs(b - _b) + abs(c - _c) if min(_a, _b, _c) > 0 else inf

    # i番目を使わないとき
    val1 = f(i + 1, _a, _b, _c)
    # i番目をAに使うとき
    val2 = f(i + 1, _a + _l[i], _b, _c) + (0 if _a == 0 else 10)
    val3 = f(i + 1, _a, _b + _l[i], _c) + (0 if _b == 0 else 10)
    val4 = f(i + 1, _a, _b, _c + _l[i]) + (0 if _c == 0 else 10)
    return min(val1, val2, val3, val4)


print((f(0, 0, 0, 0)))
# Original solution
from functools import lru_cache

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

inf = 10**9


# DP
@lru_cache(maxsize=10000)
def f(i, _a, _b, _c):
    # A,B,Cにしようとしている枝の長さが現在_a,_b,_cのとき,i番目以降の材料を使って達成される点数の最小値
    if i == n:
        return abs(a - _a) + abs(b - _b) + abs(c - _c) if min(_a, _b, _c) > 0 else inf

    # i番目を使わないとき
    val1 = f(i + 1, _a, _b, _c)
    # i番目をAに使うとき
    val2 = f(i + 1, _a + _l[i], _b, _c) + (0 if _a == 0 else 10)
    val3 = f(i + 1, _a, _b + _l[i], _c) + (0 if _b == 0 else 10)
    val4 = f(i + 1, _a, _b, _c + _l[i]) + (0 if _c == 0 else 10)
    return min(val1, val2, val3, val4)


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


# Optimized solution
from functools import lru_cache

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

inf = 10**9


# DP
@lru_cache(maxsize=1000)
def f(i, _a, _b, _c):
    # A,B,Cにしようとしている枝の長さが現在_a,_b,_cのとき,i番目以降の材料を使って達成される点数の最小値
    if i == n:
        return abs(a - _a) + abs(b - _b) + abs(c - _c) if min(_a, _b, _c) > 0 else inf

    # i番目を使わないとき
    val1 = f(i + 1, _a, _b, _c)
    # i番目をAに使うとき
    val2 = f(i + 1, _a + _l[i], _b, _c) + (0 if _a == 0 else 10)
    val3 = f(i + 1, _a, _b + _l[i], _c) + (0 if _b == 0 else 10)
    val4 = f(i + 1, _a, _b, _c + _l[i]) + (0 if _c == 0 else 10)
    return min(val1, val2, val3, val4)


print((f(0, 0, 0, 0)))
# Original solution
from collections import Counter
n, a, b, c = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(n)]


def base_n(x, n, zero_padding=8):
    retval = [[], ['0']][x == 0]
    while x > 0:
        x, r = divmod(x, n)
        retval.append(str(r))
    cnt = zero_padding - len(retval)
    pad = ['', '0'*cnt][cnt > 0]
    return pad+''.join(retval[::-1])

ans = 10**8
for i in range(4**n):
    base_4 = base_n(i, 4, n)
    n_bamboo = n - base_4.count("0")
    ctr = Counter(base_4)
    if n_bamboo < 3 or any(k not in list(ctr.keys()) for k in "123"):
        continue

    cost = 0
    for x, y in zip([a, b, c], "123"):
        cost += abs(x - sum(L[idx]for idx, v in enumerate(base_4)
                            if v == y))+(ctr[y]-1)*10
    if ans > cost:
        ans = cost
print(ans)

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


def dfs(current_index, sum_a, sum_b, sum_c):
    if current_index == n:
        if min(sum_a, sum_b, sum_c) > 0:
            return sum(abs(x-y) for x, y in
                       zip([a, b, c], [sum_a, sum_b, sum_c]))-30
        else:
            return INF

    cost_none = dfs(current_index+1, sum_a, sum_b, sum_c)
    cost_a = dfs(current_index+1, sum_a+L[current_index], sum_b, sum_c)+10
    cost_b = dfs(current_index+1, sum_a, sum_b+L[current_index], sum_c)+10
    cost_c = dfs(current_index+1, sum_a, sum_b, sum_c+L[current_index])+10
    return min(cost_none, cost_a, cost_b, cost_c)

print((dfs(0, 0, 0, 0)))
# Original solution
from itertools import combinations
from itertools import permutations


def f(x, lst, rem):
    d = abs(x - min(lst))
    min_lst = min(lst)
    tpl = None
    for v in range(len(lst) - rem + 1):
        for t in combinations(lst, v + 1):
            if abs(x - sum(t)) + 10 * v < d:
                d = abs(x - sum(t)) + 10 * v
                tpl = t
    if tpl is None:
        lst.remove(min_lst)
    else:
        for v in tpl:
            lst.remove(v)
    return d, lst


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

    ans = int(1e9+7)
    for ABC in permutations((A, B, C), 3):
        lst = L[:]
        accum = 0
        for i, v in enumerate(ABC):
            d, lst = f(v, lst, 3 - i)
            accum += d
        ans = min(ans, accum)
    print(ans)


main()


# Optimized solution
from itertools import combinations
from itertools import permutations


def f(x, lst, rem):
    d = int(1e9+7)
    tpl = ()
    for v in range(len(lst) - rem + 1):
        for t in combinations(lst, v + 1):
            if abs(x - sum(t)) + 10 * v < d:
                d = abs(x - sum(t)) + 10 * v
                tpl = t
    for v in tpl:
        lst.remove(v)
    return d, lst


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

    ans = int(1e9+7)
    for ABC in permutations((A, B, C), 3):
        lst = L[:]
        accum = 0
        for i, v in enumerate(ABC):
            d, lst = f(v, lst, 3 - i)
            accum += d
        ans = min(ans, accum)
    print(ans)


main()
# Original solution
from itertools import product
N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for i in range(N)]
INF = 10 ** 9
t1 = set([0,1,2,3])
t2= set([1,2,3])
def calc(t):
    t3 = set(t)
    if not (t3 == t1 or t3 == t2): return INF
    a, b, c = 0, 0, 0
    cnt = 0
    for i, v in enumerate(t):
        if v != 0: cnt += 1
        if v == 1: a += l[i]
        elif v == 2: b += l[i]
        elif v == 3: c += l[i]
    return abs(a-A) + abs(b-B) + abs(c-C) + (cnt-3) * 10

ans = 10 ** 9
# 4進数の配列を生成する
# 0:未使用,1:aに使用,2:bに使用,3:cに使用
for p in product(list(range(4)), repeat=N):
    ans = min(ans, calc(p))

print(ans)



# Optimized solution
from itertools import product
N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for i in range(N)]
INF = 10 ** 9
ans = INF

def calc(a, b, c):
    la, lb, lc = len(a), len(b), len(c)
    if la + lb + lc < 3 or 0 in (la, lb, lc): return INF
    sa, sb, sc = sum(a), sum(b), sum(c)
    t = 0
    return abs(sa-A) + abs(sb-B) + abs(sc-C) + (la+lb+lc-3) * 10

def dfs(n, a, b, c):
    global ans
    if n == N:
        ans = min(ans, calc(a, b, c))
        return
    dfs(n+1, a, b, c)
    dfs(n+1, a+[l[n]], b, c)
    dfs(n+1, a, b+[l[n]], c)
    dfs(n+1, a, b, c+[l[n]])

dfs(0, [], [], [])
print(ans)
# Original solution
#%%
import itertools

#%%

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



iterobj = itertools.product(list(range(4)),repeat=N)

ans = 10**8

for use in iterobj:

    if 1 in use and 2 in use and 3 in use:

        synth = [0,0,0,0]

        for m, u in  zip(materials, use):
            synth[u] += m

        mp = 10 * (use.count(1) + use.count(2) + use.count(3) - 3)

        mp += abs(A-synth[1]) + abs(B-synth[2]) + abs(C-synth[3])

        ans = min(ans, mp)

print(ans)


# Optimized solution
#%%
import sys
INPUT = sys.stdin.readline

def SINGLE_INT(): return int(INPUT())
def MULTIPLE_INT_LIST(): return list(map(int, INPUT().split()))
def MULTIPLE_INT_MAP(): return list(map(int, INPUT().split()))
def SINGLE_STRING(): return INPUT()
def MULTIPLE_STRING(): return INPUT().split()

#%%

N, A, B, C = MULTIPLE_INT_MAP()
materials = [int(eval(input())) for _ in range(N)]
INF = 10 ** 9

#%%

def dfs(cursor, a, b, c):  # 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
    # なぜ30を減じているのかというと、
    # dfs(0,0,0,0)で始まる以上、最初に選ばれるa,b,cを決定する際にもコストが10増加してしまうからである。

    # a,b,cのいずれかに1本も竹を利用していない場合は不適であるため、三項演算子を利用してその場合のコストをINFとする。

    # 再帰(4**N)
    # カーソルの当たっている竹に対して、(A or B or Cに合成する) or (合成しない)の場合に分ける
    no_compound = dfs(cursor+1, a, b, c)
    compound_to_a = dfs(cursor+1, a + materials[cursor], b, c) + 10
    compound_to_b = dfs(cursor+1, a, b + materials[cursor], c) + 10
    compound_to_c = dfs(cursor+1, a, b, c + materials[cursor]) + 10

    return min(no_compound, compound_to_a, compound_to_b, compound_to_c)

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

    min_cost = float("inf")
    for i in range(1, 2 ** n):
        bin_i = "{:08b}".format(i)[::-1]
        arr_i = [arr[x] for x in range(n) if bin_i[x] == "1"]
        cost_i = (len(arr_i) - 1) * 10
        sum_i = sum(arr_i)
    
        for j in range(1, 2 ** n):
            bin_j = "{:08b}".format(j)[::-1]
    
            if any([x == "1" and y == "1" for x, y in zip(bin_i, bin_j)]):
                continue
    
            arr_j = [arr[x] for x in range(n) if bin_j[x] == "1"]
            cost_j = (len(arr_j) - 1) * 10
            sum_j = sum(arr_j)
    
            for k in range(1, 2 ** n):
                bin_k = "{:08b}".format(k)[::-1]
    
                if any([x == "1" and y == "1" for x, y in zip(bin_i, bin_k)]):
                    continue
    
                if any([x == "1" and y == "1" for x, y in zip(bin_j, bin_k)]):
                    continue
    
                arr_k = [arr[x] for x in range(n) if bin_k[x] == "1"]
    
                cost_k = (len(arr_k) - 1) * 10
                sum_k = sum(arr_k)
    
                cost = abs(sum_i - a) + abs(sum_j - b) + abs(sum_k - c) + cost_i + cost_j + cost_k
    
                if min_cost > cost:
                    min_cost = cost
    
    print(min_cost)


main()


# Optimized solution
from itertools import product


def main():
    n, *target = list(map(int, input().split()))
    arr = [int(eval(input())) for i in range(n)]

    tests = product("0123", repeat=n)
    test_arr = [[] for _ in range(3)]
    min_cost = float("inf")

    for test in tests:
        cost = 0

        if "1" not in test or "2" not in test or "3" not in test:
            continue

        for i in range(3):
            test_arr[i] = [arr[x] for x in range(n) if test[x] == str(i + 1)]
            cost += (len(test_arr[i]) - 1) * 10
            cost += abs(sum(test_arr[i]) - target[i])

        if min_cost > cost:
            min_cost = cost

    print(min_cost)


main()