input = readlines.map{|x|x.to_i}
n = input[0]
a_list = input.slice(1, n)
sorted_a_list = a_list.uniq.sort.reverse!
# p a_list, sorted_a_list

a_list.each {|a|
    if sorted_a_list.length == 1
        p sorted_a_list.first
    elsif sorted_a_list[0] != a
        p sorted_a_list[0]
    else
        p sorted_a_list[1]
    end
}