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)



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)

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)

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)

-t1 = set([0, 1, 2, 3]) -t2 = set([1, 2, 3]) +ans = INF -def calc(t): -    t3 = set(t) -    if not (t3 == t1 or t3 == t2): +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): -    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 +    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 -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)) +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, [], [], [])