from itertools import product


def solve(T, PTTN):
    lst = [l[i] for i, t in enumerate(PTTN) if t == T]
    ANS = 10 ** 5
    if lst:
        ANS = (len(lst) - 1) * 10
        ANS += abs(sum(lst) - tgt[T])
    return ANS


tgt = list(map(int, input().split()))
l = [int(input()) for _ in range(tgt[0])]

ans = 10 ** 5
for pttn in product([0, 1, 2, 3], repeat=tgt[0]):
    tmp = sum(solve(i + 1, pttn) for i in range(3))
    ans = min(ans, tmp)
print(ans) from itertools import product def solve(T, PTTN):
    lst = [l[i] for i, t in enumerate(PTTN) if t == T]
    ANS = 10 ** 5
    if lst:
        ANS = (len(lst) - 1) * 10
        ANS += abs(sum(lst) - tgt[T])
    return ANS solve l[i] for i, t in enumerate(PTTN) if t == T for i, t in enumerate(PTTN) if t == T i t enumerate(PTTN) enumerate PTTN t == T t T if t == T l[i] l i lst = [l[i] for i, t in enumerate(PTTN) if t == T] lst [l[i] for i, t in enumerate(PTTN) if t == T] ANS = 10 ** 5 ANS 10 ** 5 10 5 if lst:
        ANS = (len(lst) - 1) * 10
        ANS += abs(sum(lst) - tgt[T])
     lst ANS = (len(lst) - 1) * 10 ANS (len(lst) - 1) * 10 len(lst) - 1 len(lst) len lst 1 10 ANS += abs(sum(lst) - tgt[T]) ANS abs(sum(lst) - tgt[T]) abs sum(lst) - tgt[T] sum(lst) sum lst tgt[T] tgt T return ANS ANS T T PTTN PTTN tgt = list(map(int, input().split())) tgt list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split int(input()) for _ in range(tgt[0]) for _ in range(tgt[0]) _ range(tgt[0]) range tgt[0] tgt 0 for _ in range(tgt[0]) int(input()) int input() input l = [int(input()) for _ in range(tgt[0])] l [int(input()) for _ in range(tgt[0])] ans = 10 ** 5 ans 10 ** 5 10 5 for pttn in product([0, 1, 2, 3], repeat=tgt[0]):
    tmp = sum(solve(i + 1, pttn) for i in range(3))
    ans = min(ans, tmp) pttn product([0, 1, 2, 3], repeat=tgt[0]) product [0, 1, 2, 3] 0 1 2 3 repeat=tgt[0] repeat tgt[0] tgt 0 tmp = sum(solve(i + 1, pttn) for i in range(3)) tmp sum(solve(i + 1, pttn) for i in range(3)) sum solve(i + 1, pttn) solve i + 1 i 1 pttn ans = min(ans, tmp) ans min(ans, tmp) min ans tmp print(ans) print ans def solve(T, PTTN):
    lst = [l[i] for i, t in enumerate(PTTN) if t == T]
    ANS = 10 ** 5
    if lst:
        ANS = (len(lst) - 1) * 10
        ANS += abs(sum(lst) - tgt[T])
    return ANS def solve(T, PTTN):
    lst = [l[i] for i, t in enumerate(PTTN) if t == T]
    ANS = 10 ** 5
    if lst:
        ANS = (len(lst) - 1) * 10
        ANS += abs(sum(lst) - tgt[T])
    return ANS solve tgt = list(map(int, input().split())) list(map(int, input().split())) tgt ans = min(ans, tmp) min(ans, tmp) ans ans = 10 ** 5 10 ** 5 ans tmp = sum(solve(i + 1, pttn) for i in range(3)) sum(solve(i + 1, pttn) for i in range(3)) tmp l = [int(input()) for _ in range(tgt[0])] [int(input()) for _ in range(tgt[0])] l
from itertools import product


def solve(T, PTTN):
    lst = [l[i] for i, t in enumerate(PTTN) if t == T]
    ANS = 10 ** 5
    if lst:
        ANS = (len(lst) - 1) * 10
        ANS += abs(sum(lst) - tgt[T])
    return ANS


tgt = list(map(int, input().split()))
l = [int(input()) for _ in range(tgt[0])]

ans = 10 ** 5
for pttn in product([0, 1, 2, 3], repeat=tgt[0]):
    tmp = sum(solve(i + 1, pttn) for i in range(3))
    ans = min(ans, tmp)
print(ans)
