program ccc

implicit none
integer :: n, i, one, two
integer, dimension(1) :: o
integer, allocatable, dimension(:) :: a

read*, n
allocate(a(n))
read*, a

one=maxval(a)
o=maxloc(a)
a(o)=0
two=maxval(a)

do i=1,n
if(i/=o(1)) write(*,'(i0)') one
if(i==o(1)) write(*,'(i0)') two
end do

end program