from itertools import product, permutations

N, A, B, C = map(int, input().split(' '))
L = [int(input()) for _ in range(N)]

ans = 10 ** 9
for groups in product(range(4), repeat=N):
    items = []
    group_a = []
    group_b = []
    group_c = []

    for group, length in zip(groups, L):
        if group == 0:
            items.append((length, 0))
        elif group == 1:
            group_a.append(length)
        elif group == 2:
            group_b.append(length)
        elif group == 3:
            group_c.append(length)

    if group_a:
        items.append((sum(group_a), (len(group_a) - 1) * 10))
    if group_b:
        items.append((sum(group_b), (len(group_b) - 1) * 10))
    if group_c:
        items.append((sum(group_c), (len(group_c) - 1) * 10))

    if len(items) < 3:
        continue

    for one, two, three in permutations((A, B, C), r=3):
        cost = 0
        _items = list(items)

        _items = sorted(_items, key=lambda x: (abs(x[0] - one), x[1]))
        cost += abs(_items[0][0] - one) + _items[0][1]
        _items.pop(0)

        _items = sorted(_items, key=lambda x: (abs(x[0] - two), x[1]))
        cost += abs(_items[0][0] - two) + _items[0][1]
        _items.pop(0)

        _items = sorted(_items, key=lambda x: (abs(x[0] - three), x[1]))
        cost += abs(_items[0][0] - three) + _items[0][1]

        ans = min(ans, cost)

print(ans) from itertools import product, permutations N, A, B, C = map(int, input().split(' ')) N map(int, input().split(' ')) map int input().split(' ') ().split () input split ' ' A B C int(input()) for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) int(input()) int input() input L = [int(input()) for _ in range(N)] L [int(input()) for _ in range(N)] ans = 10 ** 9 ans 10 ** 9 10 9 for groups in product(range(4), repeat=N):
    items = []
    group_a = []
    group_b = []
    group_c = []

    for group, length in zip(groups, L):
        if group == 0:
            items.append((length, 0))
        elif group == 1:
            group_a.append(length)
        elif group == 2:
            group_b.append(length)
        elif group == 3:
            group_c.append(length)

    if group_a:
        items.append((sum(group_a), (len(group_a) - 1) * 10))
    if group_b:
        items.append((sum(group_b), (len(group_b) - 1) * 10))
    if group_c:
        items.append((sum(group_c), (len(group_c) - 1) * 10))

    if len(items) < 3:
        continue

    for one, two, three in permutations((A, B, C), r=3):
        cost = 0
        _items = list(items)

        _items = sorted(_items, key=lambda x: (abs(x[0] - one), x[1]))
        cost += abs(_items[0][0] - one) + _items[0][1]
        _items.pop(0)

        _items = sorted(_items, key=lambda x: (abs(x[0] - two), x[1]))
        cost += abs(_items[0][0] - two) + _items[0][1]
        _items.pop(0)

        _items = sorted(_items, key=lambda x: (abs(x[0] - three), x[1]))
        cost += abs(_items[0][0] - three) + _items[0][1]

        ans = min(ans, cost) groups product(range(4), repeat=N) product range(4) range 4 repeat=N repeat N items = [] items [] group_a = [] group_a [] group_b = [] group_b [] group_c = [] group_c [] for group, length in zip(groups, L):
        if group == 0:
            items.append((length, 0))
        elif group == 1:
            group_a.append(length)
        elif group == 2:
            group_b.append(length)
        elif group == 3:
            group_c.append(length)

     group length zip(groups, L) zip groups L if group == 0:
            items.append((length, 0))
        elif group == 1:
            group_a.append(length)
        elif group == 2:
            group_b.append(length)
        elif group == 3:
            group_c.append(length)

     group == 0 group 0 items.append((length, 0)) items.append items append (length, 0) length 0 elif group == 1:
            group_a.append(length)
         group == 1 group 1 group_a.append(length) group_a.append group_a append length elif group == 2:
            group_b.append(length)
         group == 2 group 2 group_b.append(length) group_b.append group_b append length elif group == 3:
            group_c.append(length)

     group == 3 group 3 group_c.append(length) group_c.append group_c append length if group_a:
        items.append((sum(group_a), (len(group_a) - 1) * 10))
     group_a items.append((sum(group_a), (len(group_a) - 1) * 10)) items.append items append (sum(group_a), (len(group_a) - 1) * 10) sum(group_a) sum group_a (len(group_a) - 1) * 10 len(group_a) - 1 len(group_a) len group_a 1 10 if group_b:
        items.append((sum(group_b), (len(group_b) - 1) * 10))
     group_b items.append((sum(group_b), (len(group_b) - 1) * 10)) items.append items append (sum(group_b), (len(group_b) - 1) * 10) sum(group_b) sum group_b (len(group_b) - 1) * 10 len(group_b) - 1 len(group_b) len group_b 1 10 if group_c:
        items.append((sum(group_c), (len(group_c) - 1) * 10))

     group_c items.append((sum(group_c), (len(group_c) - 1) * 10)) items.append items append (sum(group_c), (len(group_c) - 1) * 10) sum(group_c) sum group_c (len(group_c) - 1) * 10 len(group_c) - 1 len(group_c) len group_c 1 10 if len(items) < 3:
        continue

     len(items) < 3 len(items) len items 3 continue for one, two, three in permutations((A, B, C), r=3):
        cost = 0
        _items = list(items)

        _items = sorted(_items, key=lambda x: (abs(x[0] - one), x[1]))
        cost += abs(_items[0][0] - one) + _items[0][1]
        _items.pop(0)

        _items = sorted(_items, key=lambda x: (abs(x[0] - two), x[1]))
        cost += abs(_items[0][0] - two) + _items[0][1]
        _items.pop(0)

        _items = sorted(_items, key=lambda x: (abs(x[0] - three), x[1]))
        cost += abs(_items[0][0] - three) + _items[0][1]

        ans = min(ans, cost) one two three permutations((A, B, C), r=3) permutations (A, B, C) A B C r=3 r 3 cost = 0 cost 0 _items = list(items) _items list(items) list items _items = sorted(_items, key=lambda x: (abs(x[0] - one), x[1])) _items sorted(_items, key=lambda x: (abs(x[0] - one), x[1])) sorted _items key=lambda x: (abs(x[0] - one), x[1]) key lambda x: (abs(x[0] - one), x[1]) (abs(x[0] - one), x[1]) abs(x[0] - one) abs x[0] - one x[0] x 0 one x[1] x 1 x cost += abs(_items[0][0] - one) + _items[0][1] cost abs(_items[0][0] - one) + _items[0][1] abs(_items[0][0] - one) abs _items[0][0] - one _items[0][0] [0] _items 0 0 one _items[0][1] [0] _items 0 1 _items.pop(0) _items.pop _items pop 0 _items = sorted(_items, key=lambda x: (abs(x[0] - two), x[1])) _items sorted(_items, key=lambda x: (abs(x[0] - two), x[1])) sorted _items key=lambda x: (abs(x[0] - two), x[1]) key lambda x: (abs(x[0] - two), x[1]) (abs(x[0] - two), x[1]) abs(x[0] - two) abs x[0] - two x[0] x 0 two x[1] x 1 x cost += abs(_items[0][0] - two) + _items[0][1] cost abs(_items[0][0] - two) + _items[0][1] abs(_items[0][0] - two) abs _items[0][0] - two _items[0][0] [0] _items 0 0 two _items[0][1] [0] _items 0 1 _items.pop(0) _items.pop _items pop 0 _items = sorted(_items, key=lambda x: (abs(x[0] - three), x[1])) _items sorted(_items, key=lambda x: (abs(x[0] - three), x[1])) sorted _items key=lambda x: (abs(x[0] - three), x[1]) key lambda x: (abs(x[0] - three), x[1]) (abs(x[0] - three), x[1]) abs(x[0] - three) abs x[0] - three x[0] x 0 three x[1] x 1 x cost += abs(_items[0][0] - three) + _items[0][1] cost abs(_items[0][0] - three) + _items[0][1] abs(_items[0][0] - three) abs _items[0][0] - three _items[0][0] [0] _items 0 0 three _items[0][1] [0] _items 0 1 ans = min(ans, cost) ans min(ans, cost) min ans cost print(ans) print ans N, A, B, C = map(int, input().split(' ')) map(int, input().split(' ')) N ans = 10 ** 9 10 ** 9 ans B, C = map(int, input().split(' ')) map(int, input().split(' ')) B _items = list(items) list(items) _items A, B, C = map(int, input().split(' ')) map(int, input().split(' ')) A C = map(int, input().split(' ')) map(int, input().split(' ')) C cost += abs(_items[0][0] - three) + _items[0][1] abs(_items[0][0] - three) + _items[0][1] cost L = [int(input()) for _ in range(N)] [int(input()) for _ in range(N)] L cost += abs(_items[0][0] - one) + _items[0][1] abs(_items[0][0] - one) + _items[0][1] cost cost += abs(_items[0][0] - two) + _items[0][1] abs(_items[0][0] - two) + _items[0][1] cost group_b = [] [] group_b _items = sorted(_items, key=lambda x: (abs(x[0] - three), x[1])) sorted(_items, key=lambda x: (abs(x[0] - three), x[1])) _items group_c = [] [] group_c _items = sorted(_items, key=lambda x: (abs(x[0] - one), x[1])) sorted(_items, key=lambda x: (abs(x[0] - one), x[1])) _items _items = sorted(_items, key=lambda x: (abs(x[0] - two), x[1])) sorted(_items, key=lambda x: (abs(x[0] - two), x[1])) _items items = [] [] items cost = 0 0 cost ans = min(ans, cost) min(ans, cost) ans group_a = [] [] group_a
from itertools import product, permutations

N, A, B, C = map(int, input().split(' '))
L = [int(input()) for _ in range(N)]

ans = 10 ** 9
for groups in product(range(4), repeat=N):
    items = []
    group_a = []
    group_b = []
    group_c = []

    for group, length in zip(groups, L):
        if group == 0:
            items.append((length, 0))
        elif group == 1:
            group_a.append(length)
        elif group == 2:
            group_b.append(length)
        elif group == 3:
            group_c.append(length)

    if group_a:
        items.append((sum(group_a), (len(group_a) - 1) * 10))
    if group_b:
        items.append((sum(group_b), (len(group_b) - 1) * 10))
    if group_c:
        items.append((sum(group_c), (len(group_c) - 1) * 10))

    if len(items) < 3:
        continue

    for one, two, three in permutations((A, B, C), r=3):
        cost = 0
        _items = list(items)

        _items = sorted(_items, key=lambda x: (abs(x[0] - one), x[1]))
        cost += abs(_items[0][0] - one) + _items[0][1]
        _items.pop(0)

        _items = sorted(_items, key=lambda x: (abs(x[0] - two), x[1]))
        cost += abs(_items[0][0] - two) + _items[0][1]
        _items.pop(0)

        _items = sorted(_items, key=lambda x: (abs(x[0] - three), x[1]))
        cost += abs(_items[0][0] - three) + _items[0][1]

        ans = min(ans, cost)

print(ans)
