import itertools
A,B,C,n=map(int,input(),split())
l=[int(input()) for i in range(n)]
ll=[]
for p in itertools.product(['A','B','C','Z'].repeat=n):
  ans=0
  a=0
  b=0
  c=0
  for i in range(n):
    if p[i]=='A':
      a+=l[i]
    elif p[i]=='B':
      b+=l[i]
    elif p[i]=='C':
      c+=l[i]
  ans+=(abs(a-A)+abs(B-b)+abs(C-c))
  ll.append(ans)
print(min(ans))
