n = gets.to_i

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

n.times do |i|
    if max_1[0] == i then
        puts max_2[1]
    else
        puts max_1[1]
    end
end