N = gets.to_i
a = Array.new(N)
for i in 0..N-1
    a[i] = gets.to_i
end
b = a.clone
b.sort!
c = a.count(b[N-1])
puts b[N-1]
if c == 1
    for i in 0..N-1
        if a[i] == b[N-1]
            puts b[N-2]
        else
            puts b[N-1]
        end
    end
else
    for i in 0..N-1
        puts b[N-1]
    end
end