program main
  implicit none
  integer i,N,maxA,maxA2,maxl
  integer, allocatable :: A(:)
  !read(*, *) (L(i), i = 1,N)
  read(*, *) N
  allocate(A(N))
  do i = 1,N
    read(*,*) A(i)
  end do
  maxA = maxval(A)
  do i = 1,N
    if (A(i) == maxA) then
      A(i) = 0
      maxl = i
      exit
    end if
  end do
  do i = 1,N
    if (i == maxl) then
      write(*,*) maxval(A)
    else
      write(*, *) maxA
    end if
  end do
end program main
