n = gets.chomp.to_i
a = readlines.map(&:chomp).map(&:to_i)

a_max = a.sort.reverse[0]
a_second = a.sort.reverse[1]

n.times do |i|
    if a[i] == a_max
        puts(a_second) 
        next
    end
    puts(a_max)
end