n = gets.chomp.to_i
arr = []
n.times do 
    s = gets.chomp.to_i
    arr << s
end
retsu = arr.sort.reverse
arr.each do |l|
    if l == retsu[0]
        puts retsu[1]
    else
        puts retsu[0]
    end
end