n = gets.to_i
list = []
n.times do |time|
    a = gets.to_i    
    list << a
end
max = list.max
sorted_list = list.sort
second_max = sorted_list[-2]
list.length.times do |n|
    if list[n] != max
        puts max
    else
        puts second_max
    end
end
