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

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



K = 4



minmp = 1e8

for x in range(pow(4, N)):

    v = x

    c = [0] * K

    s = [0] * K

    i = 0

    while v > 0:

        m = v % K

        c[m] += 1

        s[m] += L[i]

        i += 1

        v //= K



    if c[1] > 0 and c[2] > 0 and c[3] > 0:

        minmp = min(minmp, (c[1] + c[2] + c[3] - 3) * 10 + abs(s[1] - A) + abs(s[2] - B) + abs(s[3] - C))



print(minmp)

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

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



mp = sum(P) - 30



minmp = 1e10

Pcnt = [0] * 3

Ks = [-1] * N



while True:



    i = N-1

    while i >= 0:

        pre = cur = Ks[i]

        cur += 1

        if cur >= 3:

            cur = -1

        Ks[i] = cur



        for d, x in ((-1, pre), (1, cur)):



            if x >= 0:

                Pcnt[x] += d

                mp -= abs(P[x])

                P[x] -= d * L[i]

                mp += abs(P[x]) + d * 10



        if cur >= 0:

            break

        i -= 1

    else:

        break



    if min(Pcnt) > 0:

        minmp = min(minmp, mp)



print(minmp)

N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
K = 4
minmp = 1e8
for x in range(pow(4, N)):
    v = x
    c = [0] * K
    s = [0] * K
    i = 0
    while v > 0:
        m = v % K
        c[m] += 1
        s[m] += L[i]
        i += 1
        v //= K
    if c[1] > 0 and c[2] > 0 and c[3] > 0:
        minmp = min(
            minmp,
            (c[1] + c[2] + c[3] - 3) * 10
            + abs(s[1] - A)
            + abs(s[2] - B)
            + abs(s[3] - C),
        )
print(minmp)

N, *P = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
mp = sum(P) - 30
minmp = 1e10
Pcnt = [0] * 3
Ks = [-1] * N
while True:
    i = N - 1
    while i >= 0:
        pre = cur = Ks[i]
        cur += 1
        if cur >= 3:
            cur = -1
        Ks[i] = cur
        for d, x in ((-1, pre), (1, cur)):
            if x >= 0:
                Pcnt[x] += d
                mp -= abs(P[x])
                P[x] -= d * L[i]
                mp += abs(P[x]) + d * 10
        if cur >= 0:
            break
        i -= 1
    else:
        break
    if min(Pcnt) > 0:
        minmp = min(minmp, mp)
print(minmp)

-N, A, B, C = list(map(int, input().split())) +N, *P = list(map(int, input().split())) -K = 4 -minmp = 1e8 -for x in range(pow(4, N)): -    v = x -    c = [0] * K -    s = [0] * K -    i = 0 -    while v > 0: -        m = v % K -        c[m] += 1 -        s[m] += L[i] -        i += 1 -        v //= K -    if c[1] > 0 and c[2] > 0 and c[3] > 0: -        minmp = min( -            minmp, -            (c[1] + c[2] + c[3] - 3) * 10 -            + abs(s[1] - A) -            + abs(s[2] - B) -            + abs(s[3] - C), -        ) +mp = sum(P) - 30 +minmp = 1e10 +Pcnt = [0] * 3 +Ks = [-1] * N +while True: +    i = N - 1 +    while i >= 0: +        pre = cur = Ks[i] +        cur += 1 +        if cur >= 3: +            cur = -1 +        Ks[i] = cur +        for d, x in ((-1, pre), (1, cur)): +            if x >= 0: +                Pcnt[x] += d +                mp -= abs(P[x]) +                P[x] -= d * L[i] +                mp += abs(P[x]) + d * 10 +        if cur >= 0: +            break +        i -= 1 +    else: +        break +    if min(Pcnt) > 0: +        minmp = min(minmp, mp)