# XをN進数に変換

def base_number(X:int, N:int):

    res = ""

    while True:

        q, mod = divmod(X,N)

        res += str(mod)

        X = q

        if q == 0:

            break

    return res[::-1]



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

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



ans = float("inf")

for i in range(4 ** N):

    state = list(base_number(i,4).rjust(N, "0"))

    if not set(["0","1","2"]) <= set(state):

        continue

    

    make = [[] for _ in range(3)]

    for j,x in enumerate(state):

        if x == "3":

            continue

        make[int(x)].append(L[j])

    

    MP = 0

    for j,m in enumerate(make):

        if len(m) == 1:

            MP += abs(B[j] - m[0]) # 延長or短縮魔法

        else:

            MP += (len(m) - 1) * 10 # 合成魔法

            MP += abs(B[j] - sum(m))

    

    ans = min(ans, MP)



print(ans)
import sys

sys.setrecursionlimit(10 ** 7)

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



@lru_cache(None)

def dfs(cur, a, b, c):

    if cur == N:

        return abs(a - A) + abs(b - B) + abs(c - C) if min(a, b, c) > 0 else INF



    # (10 if _ else 0): 最初の1本目は合成魔法の必要がない

    ret0 = dfs(cur + 1, a, b, c)

    ret1 = dfs(cur + 1, a + l[cur], b, c) + (10 if a else 0)

    ret2 = dfs(cur + 1, a, b + l[cur], c) + (10 if b else 0)

    ret3 = dfs(cur + 1, a, b, c + l[cur]) + (10 if c else 0)



    return min(ret0, ret1, ret2, ret3)



print((dfs(0, 0, 0, 0)))
# XをN進数に変換
def base_number(X: int, N: int):
    res = ""
    while True:
        q, mod = divmod(X, N)
        res += str(mod)
        X = q
        if q == 0:
            break
    return res[::-1]


N, *B = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
ans = float("inf")
for i in range(4**N):
    state = list(base_number(i, 4).rjust(N, "0"))
    if not set(["0", "1", "2"]) <= set(state):
        continue
    make = [[] for _ in range(3)]
    for j, x in enumerate(state):
        if x == "3":
            continue
        make[int(x)].append(L[j])
    MP = 0
    for j, m in enumerate(make):
        if len(m) == 1:
            MP += abs(B[j] - m[0])  # 延長or短縮魔法
        else:
            MP += (len(m) - 1) * 10  # 合成魔法
            MP += abs(B[j] - sum(m))
    ans = min(ans, MP)
print(ans)

import sys

sys.setrecursionlimit(10**7)
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


@lru_cache(None)
def dfs(cur, a, b, c):
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) if min(a, b, c) > 0 else INF
    # (10 if _ else 0): 最初の1本目は合成魔法の必要がない
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + (10 if a else 0)
    ret2 = dfs(cur + 1, a, b + l[cur], c) + (10 if b else 0)
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + (10 if c else 0)
    return min(ret0, ret1, ret2, ret3)


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

-# XをN進数に変換 -def base_number(X: int, N: int): -    res = "" -    while True: -        q, mod = divmod(X, N) -        res += str(mod) -        X = q -        if q == 0: -            break -    return res[::-1] +import sys + +sys.setrecursionlimit(10**7) +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 -N, *B = list(map(int, input().split())) -L = [int(eval(input())) for _ in range(N)] -ans = float("inf") -for i in range(4**N): -    state = list(base_number(i, 4).rjust(N, "0")) -    if not set(["0", "1", "2"]) <= set(state): -        continue -    make = [[] for _ in range(3)] -    for j, x in enumerate(state): -        if x == "3": -            continue -        make[int(x)].append(L[j]) -    MP = 0 -    for j, m in enumerate(make): -        if len(m) == 1: -            MP += abs(B[j] - m[0])  # 延長or短縮魔法 -        else: -            MP += (len(m) - 1) * 10  # 合成魔法 -            MP += abs(B[j] - sum(m)) -    ans = min(ans, MP) -print(ans) +@lru_cache(None) +def dfs(cur, a, b, c): +    if cur == N: +        return abs(a - A) + abs(b - B) + abs(c - C) if min(a, b, c) > 0 else INF +    # (10 if _ else 0): 最初の1本目は合成魔法の必要がない +    ret0 = dfs(cur + 1, a, b, c) +    ret1 = dfs(cur + 1, a + l[cur], b, c) + (10 if a else 0) +    ret2 = dfs(cur + 1, a, b + l[cur], c) + (10 if b else 0) +    ret3 = dfs(cur + 1, a, b, c + l[cur]) + (10 if c else 0) +    return min(ret0, ret1, ret2, ret3) + + +print((dfs(0, 0, 0, 0)))