from itertools import product

def solve(NUM, LIST):
    lst = [l[i] for i, li in enumerate(LIST) if li == NUM]
    if len(lst) == 0:
        return 10 ** 5
    ANS = (len(lst) - 1) * 10
    ANS += abs(sum(lst) - target[NUM])
    return ANS

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

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

def solve(NUM, LIST):
    lst = [l[i] for i, li in enumerate(LIST) if li == NUM]
    if len(lst) == 0:
        return 10 ** 5
    ANS = (len(lst) - 1) * 10
    ANS += abs(sum(lst) - target[NUM])
    return ANS

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

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