n, a, b, c = list(map(int, input().split()))

l = [int(eval(input())) for _ in range(n)]



ans = 10**9

for m in range(4**n):

    length = [0, 0, 0, 0]

    counts = [0, 0, 0, 0]

    for d in range(n-1, -1, -1):

        i = m//(4**d)

        length[i] += l[d]

        counts[i] += 1

        m %= 4**d

        

    if 0 in length[:3]:

        continue

    ans_tmp = 0

    for i in range(3):

        ans_tmp += abs([a,b,c][i] - length[i]) + 10*(counts[i]-1)

    ans = min(ans, ans_tmp)

print(ans)

inf = 10**9

n, a, b, c = list(map(int, input().split()))

l = [int(eval(input())) for _ in range(n)]



def dfs(i, a_cur, b_cur, c_cur):

    if i == n:

        return abs(a_cur-a) + abs(b_cur-b) + abs(c_cur-c) - 30 if min(a_cur, b_cur, c_cur) > 0 else inf

    ans0 = dfs(i+1, a_cur+l[i], b_cur, c_cur) + 10

    ans1 = dfs(i+1, a_cur, b_cur+l[i], c_cur) + 10

    ans2 = dfs(i+1, a_cur, b_cur, c_cur+l[i]) + 10

    ans3 = dfs(i+1, a_cur, b_cur, c_cur)

    return min(ans0, ans1, ans2, ans3)



print((dfs(0, 0, 0, 0)))
n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
ans = 10**9
for m in range(4**n):
    length = [0, 0, 0, 0]
    counts = [0, 0, 0, 0]
    for d in range(n - 1, -1, -1):
        i = m // (4**d)
        length[i] += l[d]
        counts[i] += 1
        m %= 4**d
    if 0 in length[:3]:
        continue
    ans_tmp = 0
    for i in range(3):
        ans_tmp += abs([a, b, c][i] - length[i]) + 10 * (counts[i] - 1)
    ans = min(ans, ans_tmp)
print(ans)

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


def dfs(i, a_cur, b_cur, c_cur):
    if i == n:
        return (
            abs(a_cur - a) + abs(b_cur - b) + abs(c_cur - c) - 30
            if min(a_cur, b_cur, c_cur) > 0
            else inf
        )
    ans0 = dfs(i + 1, a_cur + l[i], b_cur, c_cur) + 10
    ans1 = dfs(i + 1, a_cur, b_cur + l[i], c_cur) + 10
    ans2 = dfs(i + 1, a_cur, b_cur, c_cur + l[i]) + 10
    ans3 = dfs(i + 1, a_cur, b_cur, c_cur)
    return min(ans0, ans1, ans2, ans3)


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

+inf = 10**9 -ans = 10**9 -for m in range(4**n): -    length = [0, 0, 0, 0] -    counts = [0, 0, 0, 0] -    for d in range(n - 1, -1, -1): -        i = m // (4**d) -        length[i] += l[d] -        counts[i] += 1 -        m %= 4**d -    if 0 in length[:3]: -        continue -    ans_tmp = 0 -    for i in range(3): -        ans_tmp += abs([a, b, c][i] - length[i]) + 10 * (counts[i] - 1) -    ans = min(ans, ans_tmp) -print(ans) + + +def dfs(i, a_cur, b_cur, c_cur): +    if i == n: +        return ( +            abs(a_cur - a) + abs(b_cur - b) + abs(c_cur - c) - 30 +            if min(a_cur, b_cur, c_cur) > 0 +            else inf +        ) +    ans0 = dfs(i + 1, a_cur + l[i], b_cur, c_cur) + 10 +    ans1 = dfs(i + 1, a_cur, b_cur + l[i], c_cur) + 10 +    ans2 = dfs(i + 1, a_cur, b_cur, c_cur + l[i]) + 10 +    ans3 = dfs(i + 1, a_cur, b_cur, c_cur) +    return min(ans0, ans1, ans2, ans3) + + +print((dfs(0, 0, 0, 0)))