program test
implicit none
integer :: n,x(200000),y(200000),a(2),i,j,k,l,t

read(*,*) n
read(*,*) (x(i),i=1,n)

y = x

l = n/2+1
k = n
do while(k /= 1)
  if(l > 1) then
    l = l-1
    t = y(l)
  else
    t = y(k)
    y(k) = y(1)
    k = k-1
    if(k == 1) then
      y(1) = t
      exit
    endif
  endif
  i = l
  j = l+l
  do while(j <= k)
    if(j < k) then
      if(y(j) < y(j+1)) j = j+1
    endif
    if (t < y(j)) then
      y(i) = y(j)
      i = j
      j = j+j
    else
      j = k+1
    endif
  enddo
  y(i) = t
enddo

a(1) = y(n/2+1)
a(2) = y(n/2)

do i= 1, n
if (x(i) >= a(1)) then
  write(*,*) a(2)
  else
  write(*,*) a(1)
endif
enddo

end program