program main
  implicit none

  integer :: n , i, a(200000),c = 0
  integer :: max1 = 0, max2 = 0, mac1 = 0, mac2 = 0

  read(*,*)n
  do i = 1, n
    read(*,*)a(i)
  end do
  max1 = MAXVAL(a)
  mac1 = MAXLOC(a)
  do i = 1, n
    if (max1 == a(i)) then
      c = c + 1
      cycle
    end if
    if (a(i) >= max2) then
      mac2 = i
      max2 = a(i)
    end if
  end do
  
  if (c >= 2) then
    do i = 1, n
      write(*,*)max1
    end do
    stop
  else
    do i = 1, n
      if (i == mac2) then
        write(*,*)max2
      else
        write(*,*)max1
      end if
    end do
    stop
  end if

end program main