n = gets.to_i

max_1 = [-1,0]
max_2 = 0
n.times do |i|
    x = gets.to_i
    if x >= max_1[1] then
        max_2 = max_1[1]
        max_1 = [i,x]
    elsif x >= max_2[1]
        max_2 = x
    end
end

ans = Array.new(n,max_1[1])
ans[max_1[0]] = max_2

puts ans