from itertools import combinations


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

dp_a = [-1] * (2 ** n)
dp_b = [-1] * (2 ** n)
dp_c = [-1] * (2 ** n)

for i in range(1, n-1):
    for j in combinations(range(n), i):
        indices = [1 << k for k in j]
        index = sum(indices)
        if i == 1:
            dp_a[index] = abs(l[j[0]] - a)
            dp_b[index] = abs(l[j[0]] - b)
            dp_c[index] = abs(l[j[0]] - c)
        else:
            dp_a[index] = min([dp_a[index - indices[k]] for k in range(i)])
            dp_a[index] = min(dp_a[index], abs(sum([l[k] for k in j]) - a) + 10 * (i-1))

            dp_b[index] = min([dp_b[index - indices[k]] for k in range(i)])
            dp_b[index] = min(dp_b[index], abs(sum([l[k] for k in j]) - b) + 10 * (i - 1))

            dp_c[index] = min([dp_c[index - indices[k]] for k in range(i)])
            dp_c[index] = min(dp_c[index], abs(sum([l[k] for k in j]) - c) + 10 * (i - 1))

ans = 10 ** 10
for i in range(1, 2 ** n):
    for j in range(1, 2 ** n):
        if i | j != i + j:
            continue
        for k in range(1, 2 ** n):
            if i + j + k == 2 ** n - 1 and i | j | k == 2 ** n - 1:
                ans = min(ans, dp_a[i] + dp_b[j] + dp_c[k])

print(ans) from itertools import combinations n, a, b, c = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split a b c l = [] l [] for i in range(n):
    l.append(int(input())) i range(n) range n l.append(int(input())) l.append l append int(input()) int input() input dp_a = [-1] * (2 ** n) dp_a [-1] * (2 ** n) [-1] -1 2 ** n 2 n dp_b = [-1] * (2 ** n) dp_b [-1] * (2 ** n) [-1] -1 2 ** n 2 n dp_c = [-1] * (2 ** n) dp_c [-1] * (2 ** n) [-1] -1 2 ** n 2 n for i in range(1, n-1):
    for j in combinations(range(n), i):
        indices = [1 << k for k in j]
        index = sum(indices)
        if i == 1:
            dp_a[index] = abs(l[j[0]] - a)
            dp_b[index] = abs(l[j[0]] - b)
            dp_c[index] = abs(l[j[0]] - c)
        else:
            dp_a[index] = min([dp_a[index - indices[k]] for k in range(i)])
            dp_a[index] = min(dp_a[index], abs(sum([l[k] for k in j]) - a) + 10 * (i-1))

            dp_b[index] = min([dp_b[index - indices[k]] for k in range(i)])
            dp_b[index] = min(dp_b[index], abs(sum([l[k] for k in j]) - b) + 10 * (i - 1))

            dp_c[index] = min([dp_c[index - indices[k]] for k in range(i)])
            dp_c[index] = min(dp_c[index], abs(sum([l[k] for k in j]) - c) + 10 * (i - 1)) i range(1, n-1) range 1 n-1 n 1 for j in combinations(range(n), i):
        indices = [1 << k for k in j]
        index = sum(indices)
        if i == 1:
            dp_a[index] = abs(l[j[0]] - a)
            dp_b[index] = abs(l[j[0]] - b)
            dp_c[index] = abs(l[j[0]] - c)
        else:
            dp_a[index] = min([dp_a[index - indices[k]] for k in range(i)])
            dp_a[index] = min(dp_a[index], abs(sum([l[k] for k in j]) - a) + 10 * (i-1))

            dp_b[index] = min([dp_b[index - indices[k]] for k in range(i)])
            dp_b[index] = min(dp_b[index], abs(sum([l[k] for k in j]) - b) + 10 * (i - 1))

            dp_c[index] = min([dp_c[index - indices[k]] for k in range(i)])
            dp_c[index] = min(dp_c[index], abs(sum([l[k] for k in j]) - c) + 10 * (i - 1)) j combinations(range(n), i) combinations range(n) range n i 1 << k for k in j for k in j k j for k in j 1 << k 1 k indices = [1 << k for k in j] indices [1 << k for k in j] index = sum(indices) index sum(indices) sum indices if i == 1:
            dp_a[index] = abs(l[j[0]] - a)
            dp_b[index] = abs(l[j[0]] - b)
            dp_c[index] = abs(l[j[0]] - c)
        else:
            dp_a[index] = min([dp_a[index - indices[k]] for k in range(i)])
            dp_a[index] = min(dp_a[index], abs(sum([l[k] for k in j]) - a) + 10 * (i-1))

            dp_b[index] = min([dp_b[index - indices[k]] for k in range(i)])
            dp_b[index] = min(dp_b[index], abs(sum([l[k] for k in j]) - b) + 10 * (i - 1))

            dp_c[index] = min([dp_c[index - indices[k]] for k in range(i)])
            dp_c[index] = min(dp_c[index], abs(sum([l[k] for k in j]) - c) + 10 * (i - 1)) i == 1 i 1 dp_a[index] = abs(l[j[0]] - a) dp_a[index] dp_a index abs(l[j[0]] - a) abs l[j[0]] - a l[j[0]] l j[0] j 0 a dp_b[index] = abs(l[j[0]] - b) dp_b[index] dp_b index abs(l[j[0]] - b) abs l[j[0]] - b l[j[0]] l j[0] j 0 b dp_c[index] = abs(l[j[0]] - c) dp_c[index] dp_c index abs(l[j[0]] - c) abs l[j[0]] - c l[j[0]] l j[0] j 0 c dp_a[index - indices[k]] for k in range(i) for k in range(i) k range(i) range i for k in range(i) dp_a[index - indices[k]] dp_a index - indices[k] index indices[k] indices k dp_a[index] = min([dp_a[index - indices[k]] for k in range(i)]) dp_a[index] dp_a index min([dp_a[index - indices[k]] for k in range(i)]) min [dp_a[index - indices[k]] for k in range(i)] l[k] for k in j for k in j k j for k in j l[k] l k dp_a[index] = min(dp_a[index], abs(sum([l[k] for k in j]) - a) + 10 * (i-1)) dp_a[index] dp_a index min(dp_a[index], abs(sum([l[k] for k in j]) - a) + 10 * (i-1)) min dp_a[index] dp_a index abs(sum([l[k] for k in j]) - a) + 10 * (i-1) abs(sum([l[k] for k in j]) - a) abs sum([l[k] for k in j]) - a sum([l[k] for k in j]) sum [l[k] for k in j] a 10 * (i-1) 10 i-1 i 1 dp_b[index - indices[k]] for k in range(i) for k in range(i) k range(i) range i for k in range(i) dp_b[index - indices[k]] dp_b index - indices[k] index indices[k] indices k dp_b[index] = min([dp_b[index - indices[k]] for k in range(i)]) dp_b[index] dp_b index min([dp_b[index - indices[k]] for k in range(i)]) min [dp_b[index - indices[k]] for k in range(i)] l[k] for k in j for k in j k j for k in j l[k] l k dp_b[index] = min(dp_b[index], abs(sum([l[k] for k in j]) - b) + 10 * (i - 1)) dp_b[index] dp_b index min(dp_b[index], abs(sum([l[k] for k in j]) - b) + 10 * (i - 1)) min dp_b[index] dp_b index abs(sum([l[k] for k in j]) - b) + 10 * (i - 1) abs(sum([l[k] for k in j]) - b) abs sum([l[k] for k in j]) - b sum([l[k] for k in j]) sum [l[k] for k in j] b 10 * (i - 1) 10 i - 1 i 1 dp_c[index - indices[k]] for k in range(i) for k in range(i) k range(i) range i for k in range(i) dp_c[index - indices[k]] dp_c index - indices[k] index indices[k] indices k dp_c[index] = min([dp_c[index - indices[k]] for k in range(i)]) dp_c[index] dp_c index min([dp_c[index - indices[k]] for k in range(i)]) min [dp_c[index - indices[k]] for k in range(i)] l[k] for k in j for k in j k j for k in j l[k] l k dp_c[index] = min(dp_c[index], abs(sum([l[k] for k in j]) - c) + 10 * (i - 1)) dp_c[index] dp_c index min(dp_c[index], abs(sum([l[k] for k in j]) - c) + 10 * (i - 1)) min dp_c[index] dp_c index abs(sum([l[k] for k in j]) - c) + 10 * (i - 1) abs(sum([l[k] for k in j]) - c) abs sum([l[k] for k in j]) - c sum([l[k] for k in j]) sum [l[k] for k in j] c 10 * (i - 1) 10 i - 1 i 1 ans = 10 ** 10 ans 10 ** 10 10 10 for i in range(1, 2 ** n):
    for j in range(1, 2 ** n):
        if i | j != i + j:
            continue
        for k in range(1, 2 ** n):
            if i + j + k == 2 ** n - 1 and i | j | k == 2 ** n - 1:
                ans = min(ans, dp_a[i] + dp_b[j] + dp_c[k]) i range(1, 2 ** n) range 1 2 ** n 2 n for j in range(1, 2 ** n):
        if i | j != i + j:
            continue
        for k in range(1, 2 ** n):
            if i + j + k == 2 ** n - 1 and i | j | k == 2 ** n - 1:
                ans = min(ans, dp_a[i] + dp_b[j] + dp_c[k]) j range(1, 2 ** n) range 1 2 ** n 2 n if i | j != i + j:
            continue
         i | j != i + j i | j i j i + j i j continue for k in range(1, 2 ** n):
            if i + j + k == 2 ** n - 1 and i | j | k == 2 ** n - 1:
                ans = min(ans, dp_a[i] + dp_b[j] + dp_c[k]) k range(1, 2 ** n) range 1 2 ** n 2 n if i + j + k == 2 ** n - 1 and i | j | k == 2 ** n - 1:
                ans = min(ans, dp_a[i] + dp_b[j] + dp_c[k]) i + j + k == 2 ** n - 1 and i | j | k == 2 ** n - 1 i + j + k == 2 ** n - 1 i + j + k i + j i j k 2 ** n - 1 2 ** n 2 n 1 i | j | k == 2 ** n - 1 i | j | k i | j i j k 2 ** n - 1 2 ** n 2 n 1 ans = min(ans, dp_a[i] + dp_b[j] + dp_c[k]) ans min(ans, dp_a[i] + dp_b[j] + dp_c[k]) min ans dp_a[i] + dp_b[j] + dp_c[k] dp_a[i] + dp_b[j] dp_a[i] dp_a i dp_b[j] dp_b j dp_c[k] dp_c k print(ans) print ans b, c = map(int, input().split()) map(int, input().split()) b indices = [1 << k for k in j] [1 << k for k in j] indices dp_b = [-1] * (2 ** n) [-1] * (2 ** n) dp_b ans = min(ans, dp_a[i] + dp_b[j] + dp_c[k]) min(ans, dp_a[i] + dp_b[j] + dp_c[k]) ans n, a, b, c = map(int, input().split()) map(int, input().split()) n a, b, c = map(int, input().split()) map(int, input().split()) a dp_c = [-1] * (2 ** n) [-1] * (2 ** n) dp_c dp_a = [-1] * (2 ** n) [-1] * (2 ** n) dp_a c = map(int, input().split()) map(int, input().split()) c l = [] [] l index = sum(indices) sum(indices) index ans = 10 ** 10 10 ** 10 ans
from itertools import combinations


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

dp_a = [-1] * (2 ** n)
dp_b = [-1] * (2 ** n)
dp_c = [-1] * (2 ** n)

for i in range(1, n-1):
    for j in combinations(range(n), i):
        indices = [1 << k for k in j]
        index = sum(indices)
        if i == 1:
            dp_a[index] = abs(l[j[0]] - a)
            dp_b[index] = abs(l[j[0]] - b)
            dp_c[index] = abs(l[j[0]] - c)
        else:
            dp_a[index] = min([dp_a[index - indices[k]] for k in range(i)])
            dp_a[index] = min(dp_a[index], abs(sum([l[k] for k in j]) - a) + 10 * (i-1))

            dp_b[index] = min([dp_b[index - indices[k]] for k in range(i)])
            dp_b[index] = min(dp_b[index], abs(sum([l[k] for k in j]) - b) + 10 * (i - 1))

            dp_c[index] = min([dp_c[index - indices[k]] for k in range(i)])
            dp_c[index] = min(dp_c[index], abs(sum([l[k] for k in j]) - c) + 10 * (i - 1))

ans = 10 ** 10
for i in range(1, 2 ** n):
    for j in range(1, 2 ** n):
        if i | j != i + j:
            continue
        for k in range(1, 2 ** n):
            if i + j + k == 2 ** n - 1 and i | j | k == 2 ** n - 1:
                ans = min(ans, dp_a[i] + dp_b[j] + dp_c[k])

print(ans)