arr = []
gets.chomp.to_i.times do |i|
  arr << gets.chomp.to_i
end

sorted_arr = arr.sort
max = sorted_arr[-1]
second = sorted_arr[-2]
arr.length.times do |idx|
  p arr[idx] == max ? second : max
end
