program many_medians
  implicit none
  integer :: n, a(200000,2), i, h(2)
  real(8) :: m
  a = 0
  read(*,*) n
  read(*,*) a(1:n,1)
  do i = 1, n
    a(i,2) = i
  end do
  call merge_sort(n,a(1:n,1:2),1)
  h(1) = a(n/2,1)
  h(2) = a(n/2+1,1)
  m = 0.5d0*real(h(1)+h(2),8)
  call merge_sort(n,a(1:n,1:2),2)
  do i = 1, n
    if (real(a(i,1),8).lt.m) then
      write(*,'(i0)') h(2)
    else
      write(*,'(i0)') h(1)
    end if
  end do
  stop
contains
  subroutine merge_sort(n,c,idx)
    implicit none
    integer, intent(in)    :: n, idx
    integer, intent(inout) :: c(n,2)
    integer                :: number, length, i, ubnd
    number = n
    length = 1
    do while (number.gt.1)
      do i = 1, number/2
        ubnd = min(2*i*length,n)
        call merge(c(2*(i-1)*length+1:(2*i-1)*length,:),c((2*i-1)*length+1:ubnd,:),idx)
      end do
      length = 2*length
      number = (number+1)/2
    end do
    return
  end subroutine merge_sort
  subroutine merge(c1,c2,idx)
    implicit none
    integer, intent(inout) :: c1(:,:), c2(:,:)
    integer, intent(in)    :: idx
    integer                :: c(size(c1(:,1))+size(c2(:,1)),size(c1(1,:)))
    integer                :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(c1(:,1))
    n2 = size(c2(:,1))
    do while ((i1.le.n1).and.(i2.le.n2))
      if (c1(i1,idx).le.c2(i2,idx)) then
        c(i1+i2-1,:) = c1(i1,:)
        i1 = i1+1
      else
        c(i1+i2-1,:) = c2(i2,:)
        i2 = i2+1
      end if
    end do
    if (i1.le.n1) then
      c(i1+i2-1:n1+n2,:) = c1(i1:n1,:)
    else if (i2 .le. n2) then
      c(i1+i2-1:n1+n2,:) = c2(i2:n2,:)
    end if
    c1 = c(1:n1,:)
    c2 = c(n1+1:n1+n2,:)
    return
  end subroutine merge
end program many_medians