program qsort
   implicit none
   integer :: n,i,ans,l
   integer,allocatable :: x(:)
   read(*,*) n
   allocate(x(n))
   do i = 1,n
      read(*,*) x(i)
   enddo
   call qs(x,n)
   l=n/2
   ans=x(l+1)-x(l)
   print*,ans
   deallocate(x)
   stop
end program qsort
 
recursive subroutine qs(x,n)
   integer,intent(in) :: n
   integer,intent(inout) :: x(n)
   integer :: p,i,imin,imax,it,is
   if(n == 1) return    
   p = x(1)   
   imin = 1   
   imax = n   
   do while(imin < imax)
      do while(x(imin) < p .and. imin < imax)
      enddo
      do while(p <= x(imax) .and. imin < imax)
         imax = imax - 1
      enddo
      if(imin < imax)then
         it = x(imax)
         x(imax) = x(imin)
         x(imin) = it
      endif
   enddo
   is = imax - 1
   if(is == 0) is = 1
   call qs(x(1:is),is)
   call qs(x(is + 1:n),n - is)
end subroutine qs