def method_name(n, ai)
  sort_desc = ai.sort.reverse
  max = sort_desc[0]
  second = sort_desc[1]
  size = ai.size

  if max == second
    size.times{puts max}
  else
    ai.each_with_index do |v, i|
      if v == max
        puts second
      else
        puts max
      end
    end
  end
end

n = gets.chomp.to_i
ai = []
n.times{ai << gets.chomp.to_i}
method_name(n, ai)