from itertools import combinations



def f(in_A,in_B,in_C,A,B,C,ex_l,counter):

    if (counter == len(ex_l)):

        return abs(in_A-A)+abs(in_B-B)+abs(in_C-C)

    else:

        tmp = ex_l[counter]

        counter +=1

        a1 = f(in_A+tmp,in_B,in_C,A,B,C,ex_l,counter)+10

        a2 = f(in_A,in_B+tmp,in_C,A,B,C,ex_l,counter)+10

        a3 = f(in_A,in_B,in_C+tmp,A,B,C,ex_l,counter)+10

        a4 = f(in_A,in_B,in_C,A,B,C,ex_l,counter)

    return min(a1,a2,a3,a4)



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

l = []

for i in range(N):

    l.append(int(eval(input())))

in_l = list(map(list,combinations(l,3)))

ex_l = [l[:] for _ in range(len(in_l))]

for i in range(len(in_l)):

    ex_l[i].remove(in_l[i][0])

    ex_l[i].remove(in_l[i][1])

    ex_l[i].remove(in_l[i][2])



mp = []

for i in range(len(in_l)):

    mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],A,B,C,ex_l[i],0))

    mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],A,C,B,ex_l[i],0))

    mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],B,A,C,ex_l[i],0))

    mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],B,C,A,ex_l[i],0))

    mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],C,A,B,ex_l[i],0))

    mp.append(f(in_l[i][0],in_l[i][1],in_l[i][2],C,B,A,ex_l[i],0))

mp = min(mp)

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

l = []

ans = []

for i in range(n):

    l.append(int(eval(input())))



def f(x,y,z,arr,ca,cb,cc):

    global a

    global b

    global c

    global ans

    if arr:

        f(x + arr[0], y, z, arr[1:],ca+1,cb,cc)

        f(x, y + arr[0], z, arr[1:],ca,cb+1,cc)

        f(x, y, z + arr[0], arr[1:],ca,cb,cc+1)

        f(x, y, z, arr[1:],ca,cb,cc)

    else:

        if x > 0 and y > 0 and z > 0:

            ans.append(abs(a-x) + abs(b-y) + abs(c-z) + 10 * (ca + cb + cc - 3))

f(0,0,0,l,0,0,0)

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


def f(in_A, in_B, in_C, A, B, C, ex_l, counter):
    if counter == len(ex_l):
        return abs(in_A - A) + abs(in_B - B) + abs(in_C - C)
    else:
        tmp = ex_l[counter]
        counter += 1
        a1 = f(in_A + tmp, in_B, in_C, A, B, C, ex_l, counter) + 10
        a2 = f(in_A, in_B + tmp, in_C, A, B, C, ex_l, counter) + 10
        a3 = f(in_A, in_B, in_C + tmp, A, B, C, ex_l, counter) + 10
        a4 = f(in_A, in_B, in_C, A, B, C, ex_l, counter)
    return min(a1, a2, a3, a4)


N, A, B, C = list(map(int, input().split()))
l = []
for i in range(N):
    l.append(int(eval(input())))
in_l = list(map(list, combinations(l, 3)))
ex_l = [l[:] for _ in range(len(in_l))]
for i in range(len(in_l)):
    ex_l[i].remove(in_l[i][0])
    ex_l[i].remove(in_l[i][1])
    ex_l[i].remove(in_l[i][2])
mp = []
for i in range(len(in_l)):
    mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], A, B, C, ex_l[i], 0))
    mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], A, C, B, ex_l[i], 0))
    mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], B, A, C, ex_l[i], 0))
    mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], B, C, A, ex_l[i], 0))
    mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], C, A, B, ex_l[i], 0))
    mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], C, B, A, ex_l[i], 0))
mp = min(mp)
print(mp)

n, a, b, c = list(map(int, input().split()))
l = []
ans = []
for i in range(n):
    l.append(int(eval(input())))


def f(x, y, z, arr, ca, cb, cc):
    global a
    global b
    global c
    global ans
    if arr:
        f(x + arr[0], y, z, arr[1:], ca + 1, cb, cc)
        f(x, y + arr[0], z, arr[1:], ca, cb + 1, cc)
        f(x, y, z + arr[0], arr[1:], ca, cb, cc + 1)
        f(x, y, z, arr[1:], ca, cb, cc)
    else:
        if x > 0 and y > 0 and z > 0:
            ans.append(abs(a - x) + abs(b - y) + abs(c - z) + 10 * (ca + cb + cc - 3))


f(0, 0, 0, l, 0, 0, 0)
print((min(ans)))

-from itertools import combinations +n, a, b, c = list(map(int, input().split())) +l = [] +ans = [] +for i in range(n): +    l.append(int(eval(input()))) -def f(in_A, in_B, in_C, A, B, C, ex_l, counter): -    if counter == len(ex_l): -        return abs(in_A - A) + abs(in_B - B) + abs(in_C - C) +def f(x, y, z, arr, ca, cb, cc): +    global a +    global b +    global c +    global ans +    if arr: +        f(x + arr[0], y, z, arr[1:], ca + 1, cb, cc) +        f(x, y + arr[0], z, arr[1:], ca, cb + 1, cc) +        f(x, y, z + arr[0], arr[1:], ca, cb, cc + 1) +        f(x, y, z, arr[1:], ca, cb, cc) -        tmp = ex_l[counter] -        counter += 1 -        a1 = f(in_A + tmp, in_B, in_C, A, B, C, ex_l, counter) + 10 -        a2 = f(in_A, in_B + tmp, in_C, A, B, C, ex_l, counter) + 10 -        a3 = f(in_A, in_B, in_C + tmp, A, B, C, ex_l, counter) + 10 -        a4 = f(in_A, in_B, in_C, A, B, C, ex_l, counter) -    return min(a1, a2, a3, a4) +        if x > 0 and y > 0 and z > 0: +            ans.append(abs(a - x) + abs(b - y) + abs(c - z) + 10 * (ca + cb + cc - 3)) -N, A, B, C = list(map(int, input().split())) -l = [] -for i in range(N): -    l.append(int(eval(input()))) -in_l = list(map(list, combinations(l, 3))) -ex_l = [l[:] for _ in range(len(in_l))] -for i in range(len(in_l)): -    ex_l[i].remove(in_l[i][0]) -    ex_l[i].remove(in_l[i][1]) -    ex_l[i].remove(in_l[i][2]) -mp = [] -for i in range(len(in_l)): -    mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], A, B, C, ex_l[i], 0)) -    mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], A, C, B, ex_l[i], 0)) -    mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], B, A, C, ex_l[i], 0)) -    mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], B, C, A, ex_l[i], 0)) -    mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], C, A, B, ex_l[i], 0)) -    mp.append(f(in_l[i][0], in_l[i][1], in_l[i][2], C, B, A, ex_l[i], 0)) -mp = min(mp) -print(mp) +f(0, 0, 0, l, 0, 0, 0) +print((min(ans)))