program synthetic_kadomatsu
  implicit none
  integer :: n, a, b, c, l(8), i, cst
  integer, parameter :: infty = 2000000000
  l = 0
  read(*,*) n, a, b, c
  do i = 1, n
    read(*,*) l(i)
  end do
  cst = 0
  call dfs(0,0,0,cst,n,a,b,c,l,1)
  write(*,'(i0)') cst
  stop
contains
  recursive subroutine dfs(x,y,z,cst,n,a,b,c,l,i)
    implicit none
    integer, intent(in) :: x, y, z, n, a, b, c, l(8), i
    integer, intent(inout) :: cst
    integer :: r1, r2, r3, r4
    if (i.gt.n) then
      cst = infty
      if (min(x,y,z).gt.0) cst = abs(x-a)+abs(y-b)+abs(z-c)-30
      return
    end if
    call dfs(x,y,z,r1,n,a,b,c,l,i+1)
    call dfs(x+l(i),y,z,r2,n,a,b,c,l,i+1)
    call dfs(x,y+l(i),z,r3,n,a,b,c,l,i+1)
    call dfs(x,y,z+l(i),r4,n,a,b,c,l,i+1)
    cst = min(r1,r2+10,r3+10,r4+10)
    return
  end subroutine dfs
end program synthetic_kadomatsu