n = gets.to_i
arr = []
n.times do
    arr.push(gets.to_i)
end

max = arr.max
max_index = arr.index(max)
arr.delete_at(max_index)
max2 = arr.max

n.times do |i|
    puts i == max_index ? max2 : max
end
