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

ans = float('inf')
loop = 0
while loop < 4**n:
    ps = [loop // (4**j) % 4 for j in range(n)]
    loop += 1
    s = [[], [], [], []]
    for cnt,p in enumerate(ps):
        s[p].append(l[cnt])
    if not all(s[1:]):
        continue
    score = [(len(s[i]) - 1) * 10 + abs(sum(s[i]) - z[i]) for i in range(4)]
    ans = min(ans, sum(score[1:]))

print(ans)
