N = gets.to_i
num_seq = []
N.times { num_seq << gets.to_i }
sorted_num_seq = num_seq.sort.reverse

results = num_seq.each_with_object([]) do |num, arr|
  max = (num == sorted_num_seq[0]) ? sorted_num_seq[1] : sorted_num_seq[0]
  arr << max
end

puts results
