program main
implicit none
integer :: n, a, b, c
integer , allocatable :: l(:),l2(:)
integer :: i, j ,k
integer :: mp
integer :: a_check, n_i, n_j
integer :: a_diff, a_state
 
read(*,*) n,a,b,c
allocate(l(n))
allocate(l2(n*(n+1)/2))
do i = 1, n
   read(*,*) l(i)
end do
call bubble(n,l)
 
mp = 0
k = 0
a_check = 1000
do i = 1, n-1
   do j = i+1, n
      k = k+1
      l2(k)= l(i)+l(j)
      if ( a_check .gt. abs(a-l2(k))) then
         a_check = abs(a - l2(k))
         n_i = i
         n_j = j
      end if
   end do
end do
do i = 1, n-1
   if (l(i).le.a .and. l(i+1) .ge. a) then
      if ( abs(a-l(i)).lt.abs(a-l(i+1)))then
         a_diff = abs(a-l(i))
      else
         a_diff = abs(a-l(i+1))
      end if
      if(a_check+10 .lt. a_diff)then
         mp = mp + a_check +10
         a_state = 1
      else
         mp = mp + a_diff
         a_state = 0
      end if
   end if
end do
write(*,'(i0)') mp
 
 
stop
contains
  subroutine bubble(n,array)
    implicit none
    integer , intent(in) :: n
    integer , intent(inout) :: array(n)
    integer :: i, j
    integer :: t
 
    do i = 1, n-1
       do j = i+1 , n
          if(array(i).gt.array(j))then
             t = array(i)
             array(i) = array(j)
             array(j) = t
          end if
       end do
    end do
  end subroutine bubble
 
end program main