n = gets.to_i
as = []
max = -1
n.times do
  as << gets.to_i
end
max_num = as.sort[-1]
max2_num = as.sort[-2]
max_cnt = as.count { |a| a == max_num }

as.each do |a|
  if max_cnt >= 2
    puts max_num
  elsif a == max_num
    puts max2_num
  else
    puts max_num
  end
end