# ABC119C
# Synthetic Kadomatsu
Enter = list(map(int, input().split()))
N = Enter[0]
L = [int(input()) for _ in range(N)]

ans = 10 ** 10

# 4 bist search
for i in range(4**N):
    mask = i
    NowCost = 0
    Group = [[] * 4 for _ in range(4)]
    for j in range(N-1, -1, -1):
        Group[mask%4].append(L[j])
        mask //= 4
    if len(Group[0]) == 0 or len(Group[1]) == 0 or len(Group[2]) == 0:
        continue
    for j in range(3):
        NowCost += 10 * (len(Group[j]) - 1)
        NowCost += abs(sum(Group[j]) - Enter[j+1])
    ans = min(ans, NowCost)
print(ans) Enter = list(map(int, input().split())) Enter list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split N = Enter[0] N Enter[0] Enter 0 int(input()) for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) int(input()) int input() input L = [int(input()) for _ in range(N)] L [int(input()) for _ in range(N)] ans = 10 ** 10 ans 10 ** 10 10 10 for i in range(4**N):
    mask = i
    NowCost = 0
    Group = [[] * 4 for _ in range(4)]
    for j in range(N-1, -1, -1):
        Group[mask%4].append(L[j])
        mask //= 4
    if len(Group[0]) == 0 or len(Group[1]) == 0 or len(Group[2]) == 0:
        continue
    for j in range(3):
        NowCost += 10 * (len(Group[j]) - 1)
        NowCost += abs(sum(Group[j]) - Enter[j+1])
    ans = min(ans, NowCost) i range(4**N) range 4**N 4 N mask = i mask i NowCost = 0 NowCost 0 [] * 4 for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [] * 4 [] 4 Group = [[] * 4 for _ in range(4)] Group [[] * 4 for _ in range(4)] for j in range(N-1, -1, -1):
        Group[mask%4].append(L[j])
        mask //= 4
     j range(N-1, -1, -1) range N-1 N 1 -1 -1 Group[mask%4].append(L[j]) [mask%4].append [mask%4] Group mask%4 mask 4 append L[j] L j mask //= 4 mask 4 if len(Group[0]) == 0 or len(Group[1]) == 0 or len(Group[2]) == 0:
        continue
     len(Group[0]) == 0 or len(Group[1]) == 0 or len(Group[2]) == 0 len(Group[0]) == 0 or len(Group[1]) == 0 len(Group[0]) == 0 len(Group[0]) len Group[0] Group 0 0 len(Group[1]) == 0 len(Group[1]) len Group[1] Group 1 0 len(Group[2]) == 0 len(Group[2]) len Group[2] Group 2 0 continue for j in range(3):
        NowCost += 10 * (len(Group[j]) - 1)
        NowCost += abs(sum(Group[j]) - Enter[j+1])
     j range(3) range 3 NowCost += 10 * (len(Group[j]) - 1) NowCost 10 * (len(Group[j]) - 1) 10 len(Group[j]) - 1 len(Group[j]) len Group[j] Group j 1 NowCost += abs(sum(Group[j]) - Enter[j+1]) NowCost abs(sum(Group[j]) - Enter[j+1]) abs sum(Group[j]) - Enter[j+1] sum(Group[j]) sum Group[j] Group j Enter[j+1] Enter j+1 j 1 ans = min(ans, NowCost) ans min(ans, NowCost) min ans NowCost print(ans) print ans L = [int(input()) for _ in range(N)] [int(input()) for _ in range(N)] L mask //= 4 4 mask NowCost += abs(sum(Group[j]) - Enter[j+1]) abs(sum(Group[j]) - Enter[j+1]) NowCost ans = 10 ** 10 10 ** 10 ans NowCost += 10 * (len(Group[j]) - 1) 10 * (len(Group[j]) - 1) NowCost Group = [[] * 4 for _ in range(4)] [[] * 4 for _ in range(4)] Group ans = min(ans, NowCost) min(ans, NowCost) ans Enter = list(map(int, input().split())) list(map(int, input().split())) Enter N = Enter[0] Enter[0] N mask = i i mask NowCost = 0 0 NowCost
# ABC119C
# Synthetic Kadomatsu
Enter = list(map(int, input().split()))
N = Enter[0]
L = [int(input()) for _ in range(N)]

ans = 10 ** 10

# 4 bist search
for i in range(4**N):
    mask = i
    NowCost = 0
    Group = [[] * 4 for _ in range(4)]
    for j in range(N-1, -1, -1):
        Group[mask%4].append(L[j])
        mask //= 4
    if len(Group[0]) == 0 or len(Group[1]) == 0 or len(Group[2]) == 0:
        continue
    for j in range(3):
        NowCost += 10 * (len(Group[j]) - 1)
        NowCost += abs(sum(Group[j]) - Enter[j+1])
    ans = min(ans, NowCost)
print(ans)
