N,*ABC=map(int,input().split())
M=3
ans=10**9
L=[]
for i in range(N):
  l=int(input())
  if l in ABC:
    ABC.remove(l)
    N-=1
    M-=1
  else:
    L.append(l)
if M==0:
  print(0)
  exit(0)
for x in range((M+1)**N):
  _=0
  abc=[0]*(M+1)
  for i in range(N):
    if x%(M+1)!=M and abc[x%(M+1)]>0:
      abc[x%(M+1)]+=L[i]
      _+=10
    else:
      abc[x%(M+1)]+=L[i]
    x=x//(M+1)
  if min(abc[:M])==0:
    continue
  for i in range(M):
    _+=abs(ABC[i]-abc[i])
  ans=min(ans,_)
  
print(ans) N,*ABC=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split *ABC ABC M=3 M 3 ans=10**9 ans 10**9 10 9 L=[] L [] for i in range(N):
  l=int(input())
  if l in ABC:
    ABC.remove(l)
    N-=1
    M-=1
  else:
    L.append(l) i range(N) range N l=int(input()) l int(input()) int input() input if l in ABC:
    ABC.remove(l)
    N-=1
    M-=1
  else:
    L.append(l) l in ABC l ABC ABC.remove(l) ABC.remove ABC remove l N-=1 N 1 M-=1 M 1 L.append(l) L.append L append l if M==0:
  print(0)
  exit(0) M==0 M 0 print(0) print 0 exit(0) exit 0 for x in range((M+1)**N):
  _=0
  abc=[0]*(M+1)
  for i in range(N):
    if x%(M+1)!=M and abc[x%(M+1)]>0:
      abc[x%(M+1)]+=L[i]
      _+=10
    else:
      abc[x%(M+1)]+=L[i]
    x=x//(M+1)
  if min(abc[:M])==0:
    continue
  for i in range(M):
    _+=abs(ABC[i]-abc[i])
  ans=min(ans,_)
   x range((M+1)**N) range (M+1)**N M+1 M 1 N _=0 _ 0 abc=[0]*(M+1) abc [0]*(M+1) [0] 0 M+1 M 1 for i in range(N):
    if x%(M+1)!=M and abc[x%(M+1)]>0:
      abc[x%(M+1)]+=L[i]
      _+=10
    else:
      abc[x%(M+1)]+=L[i]
    x=x//(M+1)
   i range(N) range N if x%(M+1)!=M and abc[x%(M+1)]>0:
      abc[x%(M+1)]+=L[i]
      _+=10
    else:
      abc[x%(M+1)]+=L[i]
     x%(M+1)!=M and abc[x%(M+1)]>0 x%(M+1)!=M x%(M+1) x M+1 M 1 M abc[x%(M+1)]>0 abc[x%(M+1)] abc x%(M+1) x M+1 M 1 0 abc[x%(M+1)]+=L[i] abc[x%(M+1)] abc x%(M+1) x M+1 M 1 L[i] L i _+=10 _ 10 abc[x%(M+1)]+=L[i] abc[x%(M+1)] abc x%(M+1) x M+1 M 1 L[i] L i x=x//(M+1) x x//(M+1) x M+1 M 1 if min(abc[:M])==0:
    continue
   min(abc[:M])==0 min(abc[:M]) min abc[:M] abc :M M 0 continue for i in range(M):
    _+=abs(ABC[i]-abc[i])
   i range(M) range M _+=abs(ABC[i]-abc[i]) _ abs(ABC[i]-abc[i]) abs ABC[i]-abc[i] ABC[i] ABC i abc[i] abc i ans=min(ans,_) ans min(ans,_) min ans _ print(ans) print ans M=3 3 M l=int(input()) int(input()) l ans=min(ans,_) min(ans,_) ans _+=10 10 _ M-=1 1 M _+=abs(ABC[i]-abc[i]) abs(ABC[i]-abc[i]) _ ans=10**9 10**9 ans L=[] [] L N,*ABC=map(int,input().split()) map(int,input().split()) N x=x//(M+1) x//(M+1) x _=0 0 _ abc=[0]*(M+1) [0]*(M+1) abc N-=1 1 N
N,*ABC=map(int,input().split())
M=3
ans=10**9
L=[]
for i in range(N):
  l=int(input())
  if l in ABC:
    ABC.remove(l)
    N-=1
    M-=1
  else:
    L.append(l)
if M==0:
  print(0)
  exit(0)
for x in range((M+1)**N):
  _=0
  abc=[0]*(M+1)
  for i in range(N):
    if x%(M+1)!=M and abc[x%(M+1)]>0:
      abc[x%(M+1)]+=L[i]
      _+=10
    else:
      abc[x%(M+1)]+=L[i]
    x=x//(M+1)
  if min(abc[:M])==0:
    continue
  for i in range(M):
    _+=abs(ABC[i]-abc[i])
  ans=min(ans,_)
  
print(ans)