def dfs(depth):

    if depth == N:

        ans.append(cal(v))

        return

    for i in range(4):

        v[depth] = i

        dfs(depth+1) 



def cal(v):

    tmp = [0] * 3 

    for i in range(N):

        if v[i] == 0:

            tmp[0] += l[i]

        elif v[i] == 1:

            tmp[1] += l[i]

        elif v[i] == 2:

            tmp[2] += l[i]

    cnt = 0

    if v.count(0) > 1:

        cnt += v.count(0) - 1

    if v.count(1) > 1:

        cnt += v.count(1) - 1

    if v.count(2) > 1:

        cnt += v.count(2) - 1



    if v.count(0) == 0 or v.count(1) == 0 or v.count(2) == 0:

        return float('inf')

    diff = cnt * 10

    for i in range(3):

        diff += abs(A[i]-tmp[i])

    

    return diff

        

    

    



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

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

v = [-1] * N



ans = []



dfs(0)

print((min(ans)))
from itertools import product



def main():

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

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

    ans = 0

    # A => 0

    # B => 1

    # C => 2

    ans = float('inf')

    for item in product(list(range(4)), repeat=N):

        length_A = 0

        cnt_A = 0

        score_A = 0

        length_B = 0

        cnt_B = 0

        score_B = 0

        length_C = 0

        cnt_C = 0

        score_C = 0

        for i,j in enumerate(item):

            if j == 0:

                length_A += L[i]

                cnt_A += 1

            if j == 1:

                length_B += L[i]

                cnt_B += 1

            if j == 2:

                length_C += L[i]

                cnt_C += 1

        if cnt_A == 0 or cnt_B == 0 or cnt_C == 0:

            continue

        score_A += abs(A - length_A) + 10 * (cnt_A - 1)

        score_B += abs(B - length_B) + 10 * (cnt_B - 1)

        score_C += abs(C - length_C) + 10 * (cnt_C - 1)

        ans = min(ans, score_A + score_B + score_C)

    print(ans)



if __name__ == "__main__":

    main()
def dfs(depth):
    if depth == N:
        ans.append(cal(v))
        return
    for i in range(4):
        v[depth] = i
        dfs(depth + 1)


def cal(v):
    tmp = [0] * 3
    for i in range(N):
        if v[i] == 0:
            tmp[0] += l[i]
        elif v[i] == 1:
            tmp[1] += l[i]
        elif v[i] == 2:
            tmp[2] += l[i]
    cnt = 0
    if v.count(0) > 1:
        cnt += v.count(0) - 1
    if v.count(1) > 1:
        cnt += v.count(1) - 1
    if v.count(2) > 1:
        cnt += v.count(2) - 1
    if v.count(0) == 0 or v.count(1) == 0 or v.count(2) == 0:
        return float("inf")
    diff = cnt * 10
    for i in range(3):
        diff += abs(A[i] - tmp[i])
    return diff


N, *A = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
v = [-1] * N
ans = []
dfs(0)
print((min(ans)))

from itertools import product


def main():
    N, A, B, C = list(map(int, input().split()))
    L = list(int(eval(input())) for _ in range(N))
    ans = 0
    # A => 0
    # B => 1
    # C => 2
    ans = float("inf")
    for item in product(list(range(4)), repeat=N):
        length_A = 0
        cnt_A = 0
        score_A = 0
        length_B = 0
        cnt_B = 0
        score_B = 0
        length_C = 0
        cnt_C = 0
        score_C = 0
        for i, j in enumerate(item):
            if j == 0:
                length_A += L[i]
                cnt_A += 1
            if j == 1:
                length_B += L[i]
                cnt_B += 1
            if j == 2:
                length_C += L[i]
                cnt_C += 1
        if cnt_A == 0 or cnt_B == 0 or cnt_C == 0:
            continue
        score_A += abs(A - length_A) + 10 * (cnt_A - 1)
        score_B += abs(B - length_B) + 10 * (cnt_B - 1)
        score_C += abs(C - length_C) + 10 * (cnt_C - 1)
        ans = min(ans, score_A + score_B + score_C)
    print(ans)


if __name__ == "__main__":
    main()

-def dfs(depth): -    if depth == N: -        ans.append(cal(v)) -        return -    for i in range(4): -        v[depth] = i -        dfs(depth + 1) +from itertools import product -def cal(v): -    tmp = [0] * 3 -    for i in range(N): -        if v[i] == 0: -            tmp[0] += l[i] -        elif v[i] == 1: -            tmp[1] += l[i] -        elif v[i] == 2: -            tmp[2] += l[i] -    cnt = 0 -    if v.count(0) > 1: -        cnt += v.count(0) - 1 -    if v.count(1) > 1: -        cnt += v.count(1) - 1 -    if v.count(2) > 1: -        cnt += v.count(2) - 1 -    if v.count(0) == 0 or v.count(1) == 0 or v.count(2) == 0: -        return float("inf") -    diff = cnt * 10 -    for i in range(3): -        diff += abs(A[i] - tmp[i]) -    return diff +def main(): +    N, A, B, C = list(map(int, input().split())) +    L = list(int(eval(input())) for _ in range(N)) +    ans = 0 +    # A => 0 +    # B => 1 +    # C => 2 +    ans = float("inf") +    for item in product(list(range(4)), repeat=N): +        length_A = 0 +        cnt_A = 0 +        score_A = 0 +        length_B = 0 +        cnt_B = 0 +        score_B = 0 +        length_C = 0 +        cnt_C = 0 +        score_C = 0 +        for i, j in enumerate(item): +            if j == 0: +                length_A += L[i] +                cnt_A += 1 +            if j == 1: +                length_B += L[i] +                cnt_B += 1 +            if j == 2: +                length_C += L[i] +                cnt_C += 1 +        if cnt_A == 0 or cnt_B == 0 or cnt_C == 0: +            continue +        score_A += abs(A - length_A) + 10 * (cnt_A - 1) +        score_B += abs(B - length_B) + 10 * (cnt_B - 1) +        score_C += abs(C - length_C) + 10 * (cnt_C - 1) +        ans = min(ans, score_A + score_B + score_C) +    print(ans) -N, *A = list(map(int, input().split())) -l = [int(eval(input())) for _ in range(N)] -v = [-1] * N -ans = [] -dfs(0) -print((min(ans))) +if __name__ == "__main__": +    main()