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

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

y = x

do i = 1, n/2 -1
y(maxloc(y)) = 0
enddo

a(1) = maxval(y)
y(maxloc(y)) = 0
a(2) = maxval(y)

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

end program