CodeEff/ECCO huggingface dataset:
# Original solution
from itertools import groupby, accumulate, product, permutations, combinations
def calc(x,X):
  n = len(x)
  ans = 10**10
  for q in product([0,1],repeat=n):
    point = 0
    cnt = 0
    for i in range(n):
      if q[i]==1:
        if cnt>0:
          point += 10
        cnt += x[i]
    if cnt>0:
      point += abs(cnt-X)
    else:
      point = 10**10
    ans = min(point,ans)
  return ans

def solve():
  ans = 10**10
  N, A, B, C = list(map(int, input().split()))
  L = [int(eval(input())) for _ in range(N)]
  for p in product(['A','B','C','D'],repeat=N):
    a,b,c = [],[],[]
    cnt = 0
    for i in range(N):
      if p[i]=='A':
        a.append(L[i])
      elif p[i]=='B':
        b.append(L[i])
      elif p[i]=='C':
        c.append(L[i])
    cnt += calc(a,A)+calc(b,B)+calc(c,C)
    ans = min(ans,cnt)
  return ans
print((solve()))

# Optimized solution
from itertools import groupby, accumulate, product, permutations, combinations
def calc(x,X):
  n = len(x)
  if n==0:
    return 10**10
  ans = abs(sum(x)-X)+(n-1)*10
  return ans

def solve():
  ans = 10**10
  N, A, B, C = list(map(int, input().split()))
  L = [int(eval(input())) for _ in range(N)]
  for p in product(['A','B','C','D'],repeat=N):
    a,b,c = [],[],[]
    cnt = 0
    for i in range(N):
      if p[i]=='A':
        a.append(L[i])
      elif p[i]=='B':
        b.append(L[i])
      elif p[i]=='C':
        c.append(L[i])
    cnt += calc(a,A)+calc(b,B)+calc(c,C)
    ans = min(ans,cnt)
  return ans
print((solve()))
# Original solution
n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]

from itertools import product
ptns = list(product([0,1,2,-1], repeat = n))

ans = 10**9
for i in range(len(ptns)):
    if 0 not in ptns[i] or 1 not in ptns[i] or 2 not in ptns[i]:
        continue
    abc = [0, 0, 0, -30]
    for j in range(n):
        tmp = ptns[i][j]
        if tmp >= 0:
            abc[tmp] += l[j]
            abc[3] += 10

    ans = min(ans, abc[3] + abs(abc[0] - a) + abs(abc[1] - b) + abs(abc[2] - c))

print(ans)

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

from itertools import product
ptns = list(product([0,1,2,-1], repeat = n))

anss = []
for i in range(len(ptns)):
    if 0 not in ptns[i] or 1 not in ptns[i] or 2 not in ptns[i]:
        continue
    abc = [0, 0, 0, -30]
    ans = 10**9
    for j in range(n):
        tmp = ptns[i][j]
        if tmp >= 0:
            abc[tmp] += l[j]
            abc[3] += 10

    anss.append(abc[3] + abs(abc[0] - a) + abs(abc[1] - b) + abs(abc[2] - c))

print((min(anss)))
# Original solution
# ＤＦＳ, パターン列挙_各竹の使用パターンを列挙

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

stack = [[0],[1],[2],[-1]] # 初期化_ここでは竹の使用パターン4つを設置
ptns = [] # パターン候補の器_初期化
 
while stack: # stackが空になるまでループ
    tmp = stack.pop() # パターンの候補を pop
    if len(tmp) == n: # 条件に合えば append
        ptns.append(tmp)
    elif len(tmp) < n: # 条件に合わなければ...
        w = tmp + [0] # パターンの候補を作成して...
        x = tmp + [1] # 〃
        y = tmp + [2] # 〃
        z = tmp + [-1]
        stack += [w, x, y, z]  # 積む

ans = 10**9
for i in range(len(ptns)):
    if 0 not in ptns[i] or 1 not in ptns[i] or 2 not in ptns[i]:
        continue
    abc = [0, 0, 0, -30]
    for j in range(n):
        tmp = ptns[i][j]
        if tmp >= 0:
            abc[tmp] += l[j]
            abc[3] += 10
    mp = abc[3]
    mp += abs(abc[0] - a)
    mp += abs(abc[1] - b)
    mp += abs(abc[2] - c)
    ans = min(ans, mp)

print(ans)


# Optimized solution
# ＤＦＳ, パターン列挙_各竹の使用パターンを列挙

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

stack = [[0],[1],[2],[-1]]

ans = 10**9
while stack:
    tmp = stack.pop()
    if len(tmp) == n:
        if 0 not in tmp or 1 not in tmp or 2 not in tmp:
            continue
        abc = [0, 0, 0, -30]
        for j in range(n):
            if tmp[j] >= 0:
                abc[tmp[j]] += l[j]
                abc[3] += 10
        mp = abc[3]
        mp += abs(abc[0] - a)
        mp += abs(abc[1] - b)
        mp += abs(abc[2] - c)
        ans = min(ans, mp)

    elif len(tmp) < n:
        w = tmp + [0]
        x = tmp + [1]
        y = tmp + [2]
        z = tmp + [-1]
        stack += [w, x, y, z]

print(ans)
# Original solution
"""
できなかった

- 操作 = 四則演算 or 関数
- 交換法則などが成り立つかどうか確認する必要がある
- 再帰的(dfs)に実装する場合、何を初期値として終了条件とするかの理解が必要
  - 前提として全探索であること => 1の解に収束する必要がない
    全ての葉を訪れたときに最小・最大値・解への到達が判定できれば良い

- dfsの実装: いまどの高さにいるかを引数として渡す = 何を高さとして定義するか
  - 階層のインデックスは選択可能な配列のインデックス
  - 同階層のノードは選択肢
  - ノードが持つ値は、その選択をした時の合計の値
  - 終了条件A, B, Cを満たす

- 求める長さA, B, Cの竹 -> 選択肢

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


def dfs(index, a, b, c):
    if N == index:
        if 0 < min(a, b, c):
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
        else:
            return 10 ** 9
    costs = []
    costs.append(dfs(index + 1, a, b, c))
    costs.append(dfs(index + 1, a + l[index], b, c) + 10)
    costs.append(dfs(index + 1, a, b + l[index], c) + 10)
    costs.append(dfs(index + 1, a, b, c + l[index]) + 10)
    return min(costs)


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

inf = 10 ** 18


def dfs(i, a, b, c):
    if n == i:
        if 0 == a or 0 == b or 0 == c:
            return inf
        return abs(A - a) + abs(B - b) + abs(C - c)

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


print((dfs(0, 0, 0, 0)))
# Original solution
n, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
inf = 10 ** 18


def dfs(i, a, b, c):
    if i == n:
        if a < 1 or b < 1 or c < 1:
            return inf
        return abs(A - a) + abs(B - b) + abs(C - c)
    res = dfs(i + 1, a, b, c)
    res = min([res, dfs(i + 1, a + l[i], b, c) + (10 if a > 0 else 0)])
    res = min([res, dfs(i + 1, a, b + l[i], c) + (10 if b > 0 else 0)])
    res = min([res, dfs(i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)])
    return res


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 dfs(i, a, b, c):
    if n == i:
        if a < 1 or b < 1 or c < 1:
            return 10 ** 18
        return abs(A - a) + abs(B - b) + abs(C - c)

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


print((dfs(0, 0, 0, 0)))
# Original solution
n, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]


def dfs(i, a, b, c):
    if n == i:
        if a < 1 or b < 1 or c < 1:
            return 10 ** 18
        return abs(A - a) + abs(B - b) + abs(C - c)

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


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 dfs(i, a, b, c):
    if i == n:
        if a < 1 or b < 1 or c < 1:
            return 10 ** 18
        return abs(A - a) + abs(B - b) + abs(C - c)

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


print((dfs(0, 0, 0, 0)))
# Original solution
n, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]


def dfs(i, a, b, c):
    if i == n:
        if a < 1 or b < 1 or c < 1:
            return 10 ** 18
        return abs(A - a) + abs(B - b) + abs(C - c)

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


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 bfs(i, a, b, c):
    if i == n:
        if a < 1 or b < 1 or c < 1:
            return 10 ** 18
        return abs(A - a) + abs(B - b) + abs(C - c)
    res = bfs(i + 1, a, b, c)
    res = min([res, bfs(i + 1, a + l[i], b, c) + (10 if a > 0 else 0)])
    res = min([res, bfs(i + 1, a, b + l[i], c) + (10 if b > 0 else 0)])
    res = min([res, bfs(i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)])
    return res


print((bfs(0, 0, 0, 0)))
# Original solution
n, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]


def dfs(i, a, b, c):
    if n == i:
        if 1 > a or 1 > b or 1 > c:
            return 10 ** 18
        return abs(A-a) + abs(B-b) + abs(C-c)
    res = dfs(i + 1, a, b, c)
    res = min([res, dfs(i + 1, a + l[i], b, c) + (10 if a > 0 else 0)])
    res = min([res, dfs(i + 1, a, b + l[i], c) + (10 if b > 0 else 0)])
    res = min([res, dfs(i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)])
    return res


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 dfs(i, a, b, c):
    if i == n:
        if a < 1 or b < 1 or c < 1:
            return 10 ** 18
        return abs(A - a) + abs(B - b) + abs(C - c)
    res = dfs(i + 1, a, b, c)
    res = min([res, dfs(i + 1, a + l[i], b, c) + (10 if a > 0 else 0)])
    res = min([res, dfs(i + 1, a, b + l[i], c) + (10 if b > 0 else 0)])
    res = min([res, dfs(i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)])
    return res


print((dfs(0, 0, 0, 0)))
# Original solution
n, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]


def dfs(i, a, b, c):
    if i == n:
        if a < 1 or b < 1 or c < 1:
            return 10 ** 18
        return abs(A-a) + abs(B-b) + abs(C-c)
    res = dfs(i + 1, a, b, c)
    res = min([res, dfs(i + 1, a + l[i], b, c) + (10 if a > 0 else 0)])
    res = min([res, dfs(i + 1, a, b + l[i], c) + (10 if b > 0 else 0)])
    res = min([res, dfs(i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)])
    return res


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 dfs(i, a, b, c):
    if i == n:
        if a < 1 or b < 1 or c < 1:
            return 10 ** 18
        return abs(A - a) + abs(B - b) + abs(C - c)
    return min([
        dfs(i + 1, a, b, c),
        dfs(i + 1, a + l[i], b, c) + (10 if a > 0 else 0),
        dfs(i + 1, a, b + l[i], c) + (10 if b > 0 else 0),
        dfs(i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)])


print((dfs(0, 0, 0, 0)))
# Original solution
n, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]


def dfs(i, a, b, c):
    if i == n:
        if a < 1 or b < 1 or c < 1:
            return 10 ** 18
        return abs(A - a) + abs(B - b) + abs(C - c)
    return min([
        dfs(i + 1, a, b, c),
        dfs(i + 1, a + l[i], b, c) + (10 if a > 0 else 0),
        dfs(i + 1, a, b + l[i], c) + (10 if b > 0 else 0),
        dfs(i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)])


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 dfs(i, a, b, c):
    if n == i:
        if a < 1 or b < 1 or c < 1:
            return 10 ** 18
        return abs(A-a) + abs(B-b) + abs(C-c)
    return min([
        dfs(i + 1, a, b, c),
        dfs(i + 1, a + l[i], b, c) + (10 if a > 0 else 0),
        dfs(i + 1, a, b + l[i], c) + (10 if b > 0 else 0),
        dfs(i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)
    ])


print((dfs(0, 0, 0, 0)))
# Original solution
N,*T = list(map(int,input().split()))
L = [int(eval(input())) for i in range(N)]
ans = 3000

for x in range(4**N):
    l = [0]*4
    t = [0]*4
    n = 4
    i = 0

    for i in range(N):
        l[x%n] += L[i]
        t[x%n] += 1
        x//=n

    if 0 in l[:3]:
        continue
    cost = 0
    for i in range(3):
        cost += (t[i]-1)*10
        cost += abs(l[i]-T[i])
    ans = min(ans, cost)

print(ans)


# Optimized solution
from itertools import product

N,*T = list(map(int,input().split()))
L = [int(eval(input())) for i in range(N)]
ans = 3000

for x in product([0,1,2,3], repeat=N):
    cost = 0
    l = [0]*4
    for i,v in enumerate(x):
        l[v] += L[i]
        if v<3:
            cost += 10

    if 0 in l[:3]:
        continue
    cost -= 30
    for i in range(3):
        cost += abs(l[i]-T[i])
    ans = min(ans, cost)

print(ans)
# Original solution
import sys
import itertools
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,A,B,C=list(map(int,input().split()))
    l=[int(eval(input())) for _ in range(N)]
    ps=itertools.permutations(l)
    ans=INF
    for p in ps:
        for i in range(N-2):
            for j in range(N-1-(i+1)):
                for k in range(N-(i+1)-(j+1)):
                    tmp=0
                    a=sum(p[:i+1])
                    b=sum(p[i+1:i+1+j+1])
                    c=sum(p[i+1+j+1:i+1+j+1+k+1])
                    tmp=(i+j+k)*10+abs(A-a)+abs(B-b)+abs(C-c)
                    ans=min(ans,tmp)
    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
import sys
import itertools
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,A,B,C=list(map(int,input().split()))
    l=[int(eval(input())) for _ in range(N)]
    ps=itertools.permutations(l)
    ans=INF
    for p in ps:
        S=[0]*(N+1)
        for i in range(N):
            S[i+1]=S[i]+p[i]
        for i in range(N-2):
            for j in range(N-1-(i+1)):
                for k in range(N-(i+1)-(j+1)):
                    tmp=0
                    a=S[i+1]
                    b=S[i+1+j+1]-S[i+1]
                    c=S[i+1+j+1+k+1]-S[i+1+j+1]
                    tmp=(i+j+k)*10+abs(A-a)+abs(B-b)+abs(C-c)
                    ans=min(ans,tmp)
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
def calc(T, bam):
    mix = len(bam) - 1
    total = sum(bam)
    return mix * 10 + abs(T - total)


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


var = [[] for _ in range(N + 1)]
var[0].append('')

for i in range(N):
    for j in var[i]:
        for c in '0abc':
            var[i + 1].append(j + c)

V = var[N]

ans = 10 ** 6
for v in V:
    a = []
    b = []
    c = []
    cost = 0
    for i, m in enumerate(v):
        if m == 'a':
            a.append(L[i])
        elif m == 'b':
            b.append(L[i])
        elif m == 'c':
            c.append(L[i])
    if len(a) and len(b) and len(c):
        CA = calc(A, a)
        CB = calc(B, b)
        CC = calc(C, c)
        cost = CA + CB + CC
        if cost == 5:
            print('hello')
        ans = min(ans, cost)

print(ans)


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

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

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


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)))
# Original solution
import bisect
INF=10**18
n,*a=list(map(int,input().split()))
l=[int(eval(input())) for _ in range(n)]
ans=INF
for i in range(4**n):
  x=[[] for _ in range(3)]
  for j in range(n):
    if (i>>2*j)&1 and not (i>>2*j+1)&1:x[0].append(l[j])
    if not (i>>2*j)&1 and (i>>2*j+1)&1:x[1].append(l[j])
    if (i>>2*j)&1 and (i>>2*j+1)&1:x[2].append(l[j])
  cnt=0
  for j in range(3):
    if len(x[j])==0:cnt=INF
    cnt+=(len(x[j])-1)*10+abs(sum(x[j])-a[j])
  ans=min(ans,cnt)
print(ans)

# Optimized solution
n,a,b,c=list(map(int,input().split()))
l=[int(eval(input())) for _ in range(n)]
ans=10**18
for i in range(4**n):
  la,lb,lc,ca,cb,cc=0,0,0,0,0,0
  for j in range(n):
    if (i>>2*j)&1 and not (i>>2*j+1)&1:
      ca+=1
      la+=l[j]
    if not (i>>2*j)&1 and (i>>2*j+1)&1:
      cb+=1
      lb+=l[j]
    if (i>>2*j)&1 and (i>>2*j+1)&1:
      cc+=1
      lc+=l[j]
  if ca*cb*cc:ans=min((ca+cb+cc-3)*10+abs(la-a)+abs(lb-b)+abs(lc-c),ans)
print(ans)
# Original solution
N, A, B, C = list(map(int, input().split()))
L_list = [int(eval(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)


# Optimized solution
N, A, B, C = list(map(int, input().split()))
L_list = [int(eval(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

'''
# Original solution
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)


# Optimized solution
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:
        global 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)
# Original solution
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:
        global 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)

# Optimized solution
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:
        global 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)