import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
import itertools

N, *A = mi()
L = [ii() for _ in range(N)]
L_ = [L[i] for i in range(N)]
N_ = N

A = sorted(A)
#sum_l = sum(L)
tmp = [0] * 3
ans = float('inf')

for k in itertools.product([0,1], repeat=N_):
    N = sum(k)
    if N < 3:
        continue
    L = []
    for x in range(N_):
        if k[x]:
            L.append(L_[x]*k[x])
    #L = [L_[x]*k[x] for x in range(N_)]
    sum_l = sum(L)

    for i in range(1, N+1):
        for koho_i in range(1, 2**i):
            for koho_j in range(1, 2**i):
                j = i
                #print(koho_i, koho_j)
                if koho_i & koho_j:
                    continue
                #tmp[0] = [L[x]*koho_i[x] for x in range(i)]
                tmp[0] = sum([L[x]*min((koho_i & 1<<x), 1) for x in range(i)])
                #tmp[1] = [L[x]*koho_j[x] for x in range(j)]
                tmp[1] = sum([L[x]*min((koho_j & 1<<x), 1) for x in range(j)])
                tmp[2] = sum_l - tmp[0] - tmp[1]
                #print(tmp)

                if 0 in tmp:
                    continue

                tmp = sorted(tmp)
                cost = (N-3) * 10 + sum([abs(tmp[x]-A[x]) for x in range(3)])
                #if cost < ans:
                    #print(tmp, cost, N)
                #if tmp[0] == 80 and tmp[1] == 91 and tmp[2] == 98:
                    #print(cost)
                ans = min(ans, cost)

print(ans) import sys sys sys.setrecursionlimit(10**8) sys.setrecursionlimit sys setrecursionlimit 10**8 10 8 def ii(): return int(sys.stdin.readline()) ii def mi(): return map(int, sys.stdin.readline().split()) mi def li(): return list(map(int, sys.stdin.readline().split())) li list(map(int, sys.stdin.readline().split())) for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) list(map(int, sys.stdin.readline().split())) list map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] li2 N N [ini]*i for _ in range(j) for _ in range(j) _ range(j) range j for _ in range(j) [ini]*i [ini] ini i def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A)) dp2 ini ini i i j j import itertools itertools N, *A = mi() N mi() mi *A A ii() for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) ii() ii L = [ii() for _ in range(N)] L [ii() for _ in range(N)] L[i] for i in range(N) for i in range(N) i range(N) range N for i in range(N) L[i] L i L_ = [L[i] for i in range(N)] L_ [L[i] for i in range(N)] N_ = N N_ N A = sorted(A) A sorted(A) sorted A tmp = [0] * 3 tmp [0] * 3 [0] 0 3 ans = float('inf') ans float('inf') float 'inf' for k in itertools.product([0,1], repeat=N_):
    N = sum(k)
    if N < 3:
        continue
    L = []
    for x in range(N_):
        if k[x]:
            L.append(L_[x]*k[x])
    #L = [L_[x]*k[x] for x in range(N_)]
    sum_l = sum(L)

    for i in range(1, N+1):
        for koho_i in range(1, 2**i):
            for koho_j in range(1, 2**i):
                j = i
                #print(koho_i, koho_j)
                if koho_i & koho_j:
                    continue
                #tmp[0] = [L[x]*koho_i[x] for x in range(i)]
                tmp[0] = sum([L[x]*min((koho_i & 1<<x), 1) for x in range(i)])
                #tmp[1] = [L[x]*koho_j[x] for x in range(j)]
                tmp[1] = sum([L[x]*min((koho_j & 1<<x), 1) for x in range(j)])
                tmp[2] = sum_l - tmp[0] - tmp[1]
                #print(tmp)

                if 0 in tmp:
                    continue

                tmp = sorted(tmp)
                cost = (N-3) * 10 + sum([abs(tmp[x]-A[x]) for x in range(3)])
                #if cost < ans:
                    #print(tmp, cost, N)
                #if tmp[0] == 80 and tmp[1] == 91 and tmp[2] == 98:
                    #print(cost)
                ans = min(ans, cost) k itertools.product([0,1], repeat=N_) itertools.product itertools product [0,1] 0 1 repeat=N_ repeat N_ N = sum(k) N sum(k) sum k if N < 3:
        continue
     N < 3 N 3 continue L = [] L [] for x in range(N_):
        if k[x]:
            L.append(L_[x]*k[x])
    #L = [L_[x]*k[x] for x in range(N_)]
     x range(N_) range N_ if k[x]:
            L.append(L_[x]*k[x])
    #L = [L_[x]*k[x] for x in range(N_)]
     k[x] k x L.append(L_[x]*k[x]) L.append L append L_[x]*k[x] L_[x] L_ x k[x] k x sum_l = sum(L) sum_l sum(L) sum L for i in range(1, N+1):
        for koho_i in range(1, 2**i):
            for koho_j in range(1, 2**i):
                j = i
                #print(koho_i, koho_j)
                if koho_i & koho_j:
                    continue
                #tmp[0] = [L[x]*koho_i[x] for x in range(i)]
                tmp[0] = sum([L[x]*min((koho_i & 1<<x), 1) for x in range(i)])
                #tmp[1] = [L[x]*koho_j[x] for x in range(j)]
                tmp[1] = sum([L[x]*min((koho_j & 1<<x), 1) for x in range(j)])
                tmp[2] = sum_l - tmp[0] - tmp[1]
                #print(tmp)

                if 0 in tmp:
                    continue

                tmp = sorted(tmp)
                cost = (N-3) * 10 + sum([abs(tmp[x]-A[x]) for x in range(3)])
                #if cost < ans:
                    #print(tmp, cost, N)
                #if tmp[0] == 80 and tmp[1] == 91 and tmp[2] == 98:
                    #print(cost)
                ans = min(ans, cost) i range(1, N+1) range 1 N+1 N 1 for koho_i in range(1, 2**i):
            for koho_j in range(1, 2**i):
                j = i
                #print(koho_i, koho_j)
                if koho_i & koho_j:
                    continue
                #tmp[0] = [L[x]*koho_i[x] for x in range(i)]
                tmp[0] = sum([L[x]*min((koho_i & 1<<x), 1) for x in range(i)])
                #tmp[1] = [L[x]*koho_j[x] for x in range(j)]
                tmp[1] = sum([L[x]*min((koho_j & 1<<x), 1) for x in range(j)])
                tmp[2] = sum_l - tmp[0] - tmp[1]
                #print(tmp)

                if 0 in tmp:
                    continue

                tmp = sorted(tmp)
                cost = (N-3) * 10 + sum([abs(tmp[x]-A[x]) for x in range(3)])
                #if cost < ans:
                    #print(tmp, cost, N)
                #if tmp[0] == 80 and tmp[1] == 91 and tmp[2] == 98:
                    #print(cost)
                ans = min(ans, cost) koho_i range(1, 2**i) range 1 2**i 2 i for koho_j in range(1, 2**i):
                j = i
                #print(koho_i, koho_j)
                if koho_i & koho_j:
                    continue
                #tmp[0] = [L[x]*koho_i[x] for x in range(i)]
                tmp[0] = sum([L[x]*min((koho_i & 1<<x), 1) for x in range(i)])
                #tmp[1] = [L[x]*koho_j[x] for x in range(j)]
                tmp[1] = sum([L[x]*min((koho_j & 1<<x), 1) for x in range(j)])
                tmp[2] = sum_l - tmp[0] - tmp[1]
                #print(tmp)

                if 0 in tmp:
                    continue

                tmp = sorted(tmp)
                cost = (N-3) * 10 + sum([abs(tmp[x]-A[x]) for x in range(3)])
                #if cost < ans:
                    #print(tmp, cost, N)
                #if tmp[0] == 80 and tmp[1] == 91 and tmp[2] == 98:
                    #print(cost)
                ans = min(ans, cost) koho_j range(1, 2**i) range 1 2**i 2 i j = i j i if koho_i & koho_j:
                    continue
                #tmp[0] = [L[x]*koho_i[x] for x in range(i)]
                 koho_i & koho_j koho_i koho_j continue L[x]*min((koho_i & 1<<x), 1) for x in range(i) for x in range(i) x range(i) range i for x in range(i) L[x]*min((koho_i & 1<<x), 1) L[x] L x min((koho_i & 1<<x), 1) min koho_i & 1<<x koho_i 1<<x 1 x 1 tmp[0] = sum([L[x]*min((koho_i & 1<<x), 1) for x in range(i)]) tmp[0] tmp 0 sum([L[x]*min((koho_i & 1<<x), 1) for x in range(i)]) sum [L[x]*min((koho_i & 1<<x), 1) for x in range(i)] L[x]*min((koho_j & 1<<x), 1) for x in range(j) for x in range(j) x range(j) range j for x in range(j) L[x]*min((koho_j & 1<<x), 1) L[x] L x min((koho_j & 1<<x), 1) min koho_j & 1<<x koho_j 1<<x 1 x 1 tmp[1] = sum([L[x]*min((koho_j & 1<<x), 1) for x in range(j)]) tmp[1] tmp 1 sum([L[x]*min((koho_j & 1<<x), 1) for x in range(j)]) sum [L[x]*min((koho_j & 1<<x), 1) for x in range(j)] tmp[2] = sum_l - tmp[0] - tmp[1] tmp[2] tmp 2 sum_l - tmp[0] - tmp[1] sum_l - tmp[0] sum_l tmp[0] tmp 0 tmp[1] tmp 1 if 0 in tmp:
                    continue

                 0 in tmp 0 tmp continue tmp = sorted(tmp) tmp sorted(tmp) sorted tmp abs(tmp[x]-A[x]) for x in range(3) for x in range(3) x range(3) range 3 for x in range(3) abs(tmp[x]-A[x]) abs tmp[x]-A[x] tmp[x] tmp x A[x] A x cost = (N-3) * 10 + sum([abs(tmp[x]-A[x]) for x in range(3)]) cost (N-3) * 10 + sum([abs(tmp[x]-A[x]) for x in range(3)]) (N-3) * 10 N-3 N 3 10 sum([abs(tmp[x]-A[x]) for x in range(3)]) sum [abs(tmp[x]-A[x]) for x in range(3)] ans = min(ans, cost) ans min(ans, cost) min ans cost print(ans) print ans def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A)) def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A)) dp2 ans = float('inf') float('inf') ans L = [] [] L def ii(): return int(sys.stdin.readline()) def ii(): return int(sys.stdin.readline()) ii def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] li2 L = [ii() for _ in range(N)] [ii() for _ in range(N)] L def mi(): return map(int, sys.stdin.readline().split()) def mi(): return map(int, sys.stdin.readline().split()) mi L_ = [L[i] for i in range(N)] [L[i] for i in range(N)] L_ N = sum(k) sum(k) N sum_l = sum(L) sum(L) sum_l A = sorted(A) sorted(A) A ans = min(ans, cost) min(ans, cost) ans def li(): return list(map(int, sys.stdin.readline().split())) def li(): return list(map(int, sys.stdin.readline().split())) li cost = (N-3) * 10 + sum([abs(tmp[x]-A[x]) for x in range(3)]) (N-3) * 10 + sum([abs(tmp[x]-A[x]) for x in range(3)]) cost tmp = [0] * 3 [0] * 3 tmp j = i i j tmp = sorted(tmp) sorted(tmp) tmp N_ = N N N_ N, *A = mi() mi() N
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
import itertools

N, *A = mi()
L = [ii() for _ in range(N)]
L_ = [L[i] for i in range(N)]
N_ = N

A = sorted(A)
#sum_l = sum(L)
tmp = [0] * 3
ans = float('inf')

for k in itertools.product([0,1], repeat=N_):
    N = sum(k)
    if N < 3:
        continue
    L = []
    for x in range(N_):
        if k[x]:
            L.append(L_[x]*k[x])
    #L = [L_[x]*k[x] for x in range(N_)]
    sum_l = sum(L)

    for i in range(1, N+1):
        for koho_i in range(1, 2**i):
            for koho_j in range(1, 2**i):
                j = i
                #print(koho_i, koho_j)
                if koho_i & koho_j:
                    continue
                #tmp[0] = [L[x]*koho_i[x] for x in range(i)]
                tmp[0] = sum([L[x]*min((koho_i & 1<<x), 1) for x in range(i)])
                #tmp[1] = [L[x]*koho_j[x] for x in range(j)]
                tmp[1] = sum([L[x]*min((koho_j & 1<<x), 1) for x in range(j)])
                tmp[2] = sum_l - tmp[0] - tmp[1]
                #print(tmp)

                if 0 in tmp:
                    continue

                tmp = sorted(tmp)
                cost = (N-3) * 10 + sum([abs(tmp[x]-A[x]) for x in range(3)])
                #if cost < ans:
                    #print(tmp, cost, N)
                #if tmp[0] == 80 and tmp[1] == 91 and tmp[2] == 98:
                    #print(cost)
                ans = min(ans, cost)

print(ans)
