integer(8) N
integer(8),allocatable,dimension(:)::a,b
integer(8) med_l,med_b
read*,N
allocate(a(N),b(N))
read*,a
b=a
call heapsort(n,b)
med_l=b(N/2)
med_b=b(N/2+1)

do i=1,N
  if(a(i)<=med_l)then
    print"(i0)",med_b
  else
    print"(i0)",med_l
  endif
end do

contains

subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer(8),intent(in) :: n
  integer(8),intent(inout) :: array(1:n)
  integer(8)::i,k,j,l
  integer(8):: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort

end