program kadomatsu
  implicit none
  integer :: n,a,b,c,i,j,k,count,distro
  integer :: bar(4)
  integer, allocatable :: l(:)
  integer, allocatable :: mp(:)

  read *, n,a,b,c
  allocate(l(n))
  do i = 1, n
    read*, l(i)
  end do
  allocate(mp(4**n))
    do j = 1, 4**n!pattern of junction
      bar = 0
      mp(j) = 0
      count = j
      do k = n,1,-1!number of bamboo
        distro = count/4**(k-1) + 1
        bar(distro) = bar(distro) + l(k)
        if (distro /= 4) mp(j) = mp(j) + 10
        count = mod(count,4**(k-1))
      end do
      if (bar(1)*bar(2)*bar(3) == 0) then
        mp(j) = 10000
      else
        mp(j) = mp(j) + abs(a-bar(1)) + abs(b-bar(2)) + abs (c-bar(3)) - 30
      end if
    end do
  print '(i0)', minval(mp)
  stop
end program kadomatsu
