module procedure_module
  implicit none
  public

  contains

  recursive function dfs(n, l, ta, tb, tc, cur, a, b, c) result(cost)
    integer, intent(in) :: n, l(:), cur, ta, tb, tc, a, b, c
    integer :: cost, r0, r1, r2, r3
    if (cur > n) then
      if (minval([a, b, c]) > 0) then
        cost = abs(a - ta) + abs(b - tb) + abs(c - tc) - 30
      else
        cost = huge(cost) / 2
      end if
    else
      r0 = dfs(n, l, ta, tb, tc, cur + 1, a, b, c)
      r1 = dfs(n, l, ta, tb, tc, cur + 1, a + l(cur), b, c) + 10
      r2 = dfs(n, l, ta, tb, tc, cur + 1, a, b + l(cur), c) + 10
      r3 = dfs(n, l, ta, tb, tc, cur + 1, a, b, c + l(cur)) + 10
      cost = minval([r0, r1, r2, r3])
    end if
  end function dfs
end module procedure_module

program main
  use procedure_module
  implicit none
  integer :: n, a, b, c
  integer, allocatable :: l(:)
  read (*, *) n, a, b, c
  allocate (l(n))
  read (*, *) l(:)
  write (*, "(i0)") dfs(n, l(:), a, b, c, 1, 0, 0, 0)
end program main
