program probC
    implicit none
    integer::n, i, maxv
    integer, allocatable::a(:), c(:)
    read(*,*) n
    allocate(a(n),c(n))
    do i = 1, n
        read(*,*) a(i)
    end do
    c = a
    maxv = maxval(a)
    do i = 1, n
        if(a(i) == maxv) then
            c(i) = 0
            exit
        end if
    end do
    do i = 1, n
        if(a(i) == maxv) then
            write(*,*) maxval(c)
        else    
            write(*,*) maxv
        end if
    end do
    deallocate(a,c)
    stop
end program