n = gets.to_i

a = n.times.map { gets.to_i }

first, second = a.uniq.sort.reverse.first(2)

if a.count(first) == 1
  a.each do |x|
    puts (if x == first then second else first end)
  end
else
  n.times { puts first }
end
