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

takelist = [a,b,c]



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

li2 = [0 for _ in range(n)]

min = 10**100



def movelist(li,n):

    for i in range(n):

        if li[i] != 3:

            li[i] += 1

            break

        else:

            li[i] = 0



for i in range(4**n):

    li3 = [0,0,0,0]

    sum = 0

    for j in range(n):

        if li3[li2[j]] != 0 and li2[j] != 3:

            sum += 10

        li3[li2[j]] += li[j]

    if li3[0] != 0 and li3[1] != 0 and li3[2] != 0:

        for k in range(3):

            sum += abs(li3[k] - takelist[k])

        if sum < min:

            min = sum

    movelist(li2,n)



print(min)

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

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



def searchans(count,a,b,c):

    if count == n:

        if not 0 in [a,b,c]:

            return abs(A-a) + abs(B-b) + abs(C-c) - 30

        else:

            return 10**100

    else:

        ret0 = searchans(count+1,a,b,c)

        ret1 = searchans(count+1,a+li[count],b,c) + 10

        ret2 = searchans(count+1,a,b+li[count],c) + 10

        ret3 = searchans(count+1,a,b,c+li[count]) + 10

        return min([ret0,ret1,ret2,ret3])



print((searchans(0,0,0,0)))

n, a, b, c = list(map(int, input().split()))
takelist = [a, b, c]
li = [int(eval(input())) for _ in range(n)]
li2 = [0 for _ in range(n)]
min = 10**100


def movelist(li, n):
    for i in range(n):
        if li[i] != 3:
            li[i] += 1
            break
        else:
            li[i] = 0


for i in range(4**n):
    li3 = [0, 0, 0, 0]
    sum = 0
    for j in range(n):
        if li3[li2[j]] != 0 and li2[j] != 3:
            sum += 10
        li3[li2[j]] += li[j]
    if li3[0] != 0 and li3[1] != 0 and li3[2] != 0:
        for k in range(3):
            sum += abs(li3[k] - takelist[k])
        if sum < min:
            min = sum
    movelist(li2, n)
print(min)

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


def searchans(count, a, b, c):
    if count == n:
        if not 0 in [a, b, c]:
            return abs(A - a) + abs(B - b) + abs(C - c) - 30
        else:
            return 10**100
    else:
        ret0 = searchans(count + 1, a, b, c)
        ret1 = searchans(count + 1, a + li[count], b, c) + 10
        ret2 = searchans(count + 1, a, b + li[count], c) + 10
        ret3 = searchans(count + 1, a, b, c + li[count]) + 10
        return min([ret0, ret1, ret2, ret3])


print((searchans(0, 0, 0, 0)))

-n, a, b, c = list(map(int, input().split())) -takelist = [a, b, c] +n, A, B, C = list(map(int, input().split())) -li2 = [0 for _ in range(n)] -min = 10**100 -def movelist(li, n): -    for i in range(n): -        if li[i] != 3: -            li[i] += 1 -            break +def searchans(count, a, b, c): +    if count == n: +        if not 0 in [a, b, c]: +            return abs(A - a) + abs(B - b) + abs(C - c) - 30 -            li[i] = 0 +            return 10**100 +    else: +        ret0 = searchans(count + 1, a, b, c) +        ret1 = searchans(count + 1, a + li[count], b, c) + 10 +        ret2 = searchans(count + 1, a, b + li[count], c) + 10 +        ret3 = searchans(count + 1, a, b, c + li[count]) + 10 +        return min([ret0, ret1, ret2, ret3]) -for i in range(4**n): -    li3 = [0, 0, 0, 0] -    sum = 0 -    for j in range(n): -        if li3[li2[j]] != 0 and li2[j] != 3: -            sum += 10 -        li3[li2[j]] += li[j] -    if li3[0] != 0 and li3[1] != 0 and li3[2] != 0: -        for k in range(3): -            sum += abs(li3[k] - takelist[k]) -        if sum < min: -            min = sum -    movelist(li2, n) -print(min) +print((searchans(0, 0, 0, 0)))