module m_quick
  implicit none
contains
  subroutine qsort(x)
    integer, intent(in out) :: x(:)
    integer, allocatable :: indx(:), iwk(:) 
    integer :: n
    allocate( indx(size(x)) )
    allocate( iwk (size(x)) ) 
    n = size(x)
    call qsort2(n, x, indx, iwk)
    return
  end subroutine qsort
  
  subroutine qsort2(n, x, indx, iwk)
    integer, intent(in) :: n
    integer, intent(in out) :: x(n)
    integer, intent(out) :: indx(n), iwk(n)
    integer :: i, j, kk0, kk1, k0, k1, ix0, ix1, iindx, nindx
    real :: tmp
    if (n < 2) return
    indx(1) = 1
    indx(2) = n !size(x)  
    nindx = 2
    do
      if (nindx == 0) exit
      iindx = 0
      do j = 1, nindx - 1, 2
        kk0 = indx(j) 
        kk1 = indx(j + 1) 
        k0 = kk0 + 1
        k1 = kk1
        do
          if (k0 > k1) exit
          do ix0 = k0, k1              ! L
            if (x(ix0) > x(kk0)) exit 
          end do
          do ix1 = k1, k0, -1          ! R
            if (x(ix1) < x(kk0)) exit 
          end do
          if (ix0 >= ix1) exit
          tmp = x(ix0)                 !swap
          x(ix0) = x(ix1)
          x(ix1) = tmp
          k0 = ix0 + 1
          k1 = ix1 - 1
        end do
        tmp = x(kk0)                   ! CSHIFT(x(kk0:ix1), 1)
        do i = kk0, ix1 - 1
          x(i) = x(i + 1)
        end do
        x(ix1) = tmp
        if (kk0 < ix1 - 1) then         ! L
          iindx = iindx + 1
          iwk(iindx) = kk0 
          iindx = iindx + 1
          iwk(iindx) = ix1 - 1
        end if
        if (kk1 > ix0) then             ! R
          iindx = iindx + 1
          iwk(iindx) = ix0
          iindx = iindx + 1
          iwk(iindx) = kk1
        end if 
      end do
      nindx = iindx
      indx(1:nindx) = iwk(1:nindx)
    end do
    return
  end subroutine qsort2
end module m_quick


program main
  use m_quick
  implicit none
  	integer::N,i,k
    integer,allocatable::x(:)
    read(*,*)N
    allocate(x(N))
    read(*,*)(x(i),i=1,N)
    call qsort(x)
    k=N/2
  print*,x(k+1)-x(k)
  stop
end program main