from collections import defaultdict
from itertools import combinations, permutations
from operator import itemgetter
n, a, b, c, *L = map(int, open(0).read().split())
L.sort()
A = [a, b, c]
dicts = [defaultdict(lambda: 10**5) for _ in range(3)]
for i in range(n-2):
    for x in combinations(enumerate(L), i+1):
        k = tuple(i for i, l in x)
        v = sum(l for i, l in x)
        for d, x in zip(dicts, A):
            d[k] = min(d[k], abs(x-v) + 10*i)
scores = [sorted(d.items(), key=itemgetter(1)) for d in dicts]

ans = 10**5
for p1, p2, p3 in permutations(range(3)):
    k1, v1 = scores[p1][0]
    k1 = set(k1)
    for k2, v2 in scores[p2]:
        k2 = set(k2)
        if len(k1 & k2) == 0:
            break
    for k3, v3 in scores[p3]:
        k3 = set(k3)
        if len(k1 & k3) + len(k2 & k3) == 0:
            break
    ans = min(ans, sum([v1, v2, v3]))
print(ans) from collections import defaultdict from itertools import combinations, permutations from operator import itemgetter n, a, b, c, *L = map(int, open(0).read().split()) n map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split a b c *L L L.sort() L.sort L sort A = [a, b, c] A [a, b, c] a b c defaultdict(lambda: 10**5) for _ in range(3) for _ in range(3) _ range(3) range 3 for _ in range(3) defaultdict(lambda: 10**5) defaultdict lambda: 10**5 10**5 10 5 dicts = [defaultdict(lambda: 10**5) for _ in range(3)] dicts [defaultdict(lambda: 10**5) for _ in range(3)] for i in range(n-2):
    for x in combinations(enumerate(L), i+1):
        k = tuple(i for i, l in x)
        v = sum(l for i, l in x)
        for d, x in zip(dicts, A):
            d[k] = min(d[k], abs(x-v) + 10*i) i range(n-2) range n-2 n 2 for x in combinations(enumerate(L), i+1):
        k = tuple(i for i, l in x)
        v = sum(l for i, l in x)
        for d, x in zip(dicts, A):
            d[k] = min(d[k], abs(x-v) + 10*i) x combinations(enumerate(L), i+1) combinations enumerate(L) enumerate L i+1 i 1 k = tuple(i for i, l in x) k tuple(i for i, l in x) tuple i v = sum(l for i, l in x) v sum(l for i, l in x) sum l for d, x in zip(dicts, A):
            d[k] = min(d[k], abs(x-v) + 10*i) d x zip(dicts, A) zip dicts A d[k] = min(d[k], abs(x-v) + 10*i) d[k] d k min(d[k], abs(x-v) + 10*i) min d[k] d k abs(x-v) + 10*i abs(x-v) abs x-v x v 10*i 10 i sorted(d.items(), key=itemgetter(1)) for d in dicts for d in dicts d dicts for d in dicts sorted(d.items(), key=itemgetter(1)) sorted d.items() d.items d items key=itemgetter(1) key itemgetter(1) itemgetter 1 scores = [sorted(d.items(), key=itemgetter(1)) for d in dicts] scores [sorted(d.items(), key=itemgetter(1)) for d in dicts] ans = 10**5 ans 10**5 10 5 for p1, p2, p3 in permutations(range(3)):
    k1, v1 = scores[p1][0]
    k1 = set(k1)
    for k2, v2 in scores[p2]:
        k2 = set(k2)
        if len(k1 & k2) == 0:
            break
    for k3, v3 in scores[p3]:
        k3 = set(k3)
        if len(k1 & k3) + len(k2 & k3) == 0:
            break
    ans = min(ans, sum([v1, v2, v3])) p1 p2 p3 permutations(range(3)) permutations range(3) range 3 k1, v1 = scores[p1][0] k1 scores[p1][0] [p1] scores p1 0 v1 k1 = set(k1) k1 set(k1) set k1 for k2, v2 in scores[p2]:
        k2 = set(k2)
        if len(k1 & k2) == 0:
            break
     k2 v2 scores[p2] scores p2 k2 = set(k2) k2 set(k2) set k2 if len(k1 & k2) == 0:
            break
     len(k1 & k2) == 0 len(k1 & k2) len k1 & k2 k1 k2 0 break for k3, v3 in scores[p3]:
        k3 = set(k3)
        if len(k1 & k3) + len(k2 & k3) == 0:
            break
     k3 v3 scores[p3] scores p3 k3 = set(k3) k3 set(k3) set k3 if len(k1 & k3) + len(k2 & k3) == 0:
            break
     len(k1 & k3) + len(k2 & k3) == 0 len(k1 & k3) + len(k2 & k3) len(k1 & k3) len k1 & k3 k1 k3 len(k2 & k3) len k2 & k3 k2 k3 0 break ans = min(ans, sum([v1, v2, v3])) ans min(ans, sum([v1, v2, v3])) min ans sum([v1, v2, v3]) sum [v1, v2, v3] v1 v2 v3 print(ans) print ans k1 = set(k1) set(k1) k1 k1, v1 = scores[p1][0] scores[p1][0] k1 k2 = set(k2) set(k2) k2 n, a, b, c, *L = map(int, open(0).read().split()) map(int, open(0).read().split()) n ans = 10**5 10**5 ans c, *L = map(int, open(0).read().split()) map(int, open(0).read().split()) c A = [a, b, c] [a, b, c] A v = sum(l for i, l in x) sum(l for i, l in x) v v1 = scores[p1][0] scores[p1][0] v1 k3 = set(k3) set(k3) k3 dicts = [defaultdict(lambda: 10**5) for _ in range(3)] [defaultdict(lambda: 10**5) for _ in range(3)] dicts k = tuple(i for i, l in x) tuple(i for i, l in x) k a, b, c, *L = map(int, open(0).read().split()) map(int, open(0).read().split()) a scores = [sorted(d.items(), key=itemgetter(1)) for d in dicts] [sorted(d.items(), key=itemgetter(1)) for d in dicts] scores b, c, *L = map(int, open(0).read().split()) map(int, open(0).read().split()) b ans = min(ans, sum([v1, v2, v3])) min(ans, sum([v1, v2, v3])) ans
from collections import defaultdict
from itertools import combinations, permutations
from operator import itemgetter
n, a, b, c, *L = map(int, open(0).read().split())
L.sort()
A = [a, b, c]
dicts = [defaultdict(lambda: 10**5) for _ in range(3)]
for i in range(n-2):
    for x in combinations(enumerate(L), i+1):
        k = tuple(i for i, l in x)
        v = sum(l for i, l in x)
        for d, x in zip(dicts, A):
            d[k] = min(d[k], abs(x-v) + 10*i)
scores = [sorted(d.items(), key=itemgetter(1)) for d in dicts]

ans = 10**5
for p1, p2, p3 in permutations(range(3)):
    k1, v1 = scores[p1][0]
    k1 = set(k1)
    for k2, v2 in scores[p2]:
        k2 = set(k2)
        if len(k1 & k2) == 0:
            break
    for k3, v3 in scores[p3]:
        k3 = set(k3)
        if len(k1 & k3) + len(k2 & k3) == 0:
            break
    ans = min(ans, sum([v1, v2, v3]))
print(ans)