s=list(map(int, input().split()))
n=s[0]
a=s[1:]
l=[int(input()) for i in range(n)]
num=4**n
ans=1000000000
for i in range(num):
  t=i
  use=[[] for _ in range(4)]
  for j in range(n):
    use[t%4].append(l[j])
    t//=4
  cost=0
  for j in range(3):
    if len(use[j])==0:
      cost=100000000000
    else:
      cost+=(len(use[j])-1)*10+abs(sum(use[j])-a[j])
  ans=min(ans,cost)
print(ans) s=list(map(int, input().split())) s list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split n=s[0] n s[0] s 0 a=s[1:] a s[1:] s 1: 1 int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input l=[int(input()) for i in range(n)] l [int(input()) for i in range(n)] num=4**n num 4**n 4 n ans=1000000000 ans 1000000000 for i in range(num):
  t=i
  use=[[] for _ in range(4)]
  for j in range(n):
    use[t%4].append(l[j])
    t//=4
  cost=0
  for j in range(3):
    if len(use[j])==0:
      cost=100000000000
    else:
      cost+=(len(use[j])-1)*10+abs(sum(use[j])-a[j])
  ans=min(ans,cost) i range(num) range num t=i t i [] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [] use=[[] for _ in range(4)] use [[] for _ in range(4)] for j in range(n):
    use[t%4].append(l[j])
    t//=4
   j range(n) range n use[t%4].append(l[j]) [t%4].append [t%4] use t%4 t 4 append l[j] l j t//=4 t 4 cost=0 cost 0 for j in range(3):
    if len(use[j])==0:
      cost=100000000000
    else:
      cost+=(len(use[j])-1)*10+abs(sum(use[j])-a[j])
   j range(3) range 3 if len(use[j])==0:
      cost=100000000000
    else:
      cost+=(len(use[j])-1)*10+abs(sum(use[j])-a[j])
   len(use[j])==0 len(use[j]) len use[j] use j 0 cost=100000000000 cost 100000000000 cost+=(len(use[j])-1)*10+abs(sum(use[j])-a[j]) cost (len(use[j])-1)*10+abs(sum(use[j])-a[j]) (len(use[j])-1)*10 len(use[j])-1 len(use[j]) len use[j] use j 1 10 abs(sum(use[j])-a[j]) abs sum(use[j])-a[j] sum(use[j]) sum use[j] use j a[j] a j ans=min(ans,cost) ans min(ans,cost) min ans cost print(ans) print ans s=list(map(int, input().split())) list(map(int, input().split())) s ans=1000000000 1000000000 ans t=i i t cost=0 0 cost n=s[0] s[0] n num=4**n 4**n num use=[[] for _ in range(4)] [[] for _ in range(4)] use l=[int(input()) for i in range(n)] [int(input()) for i in range(n)] l ans=min(ans,cost) min(ans,cost) ans a=s[1:] s[1:] a cost+=(len(use[j])-1)*10+abs(sum(use[j])-a[j]) (len(use[j])-1)*10+abs(sum(use[j])-a[j]) cost t//=4 4 t cost=100000000000 100000000000 cost
s=list(map(int, input().split()))
n=s[0]
a=s[1:]
l=[int(input()) for i in range(n)]
num=4**n
ans=1000000000
for i in range(num):
  t=i
  use=[[] for _ in range(4)]
  for j in range(n):
    use[t%4].append(l[j])
    t//=4
  cost=0
  for j in range(3):
    if len(use[j])==0:
      cost=100000000000
    else:
      cost+=(len(use[j])-1)*10+abs(sum(use[j])-a[j])
  ans=min(ans,cost)
print(ans)