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

max = 0
max_index = 0
nmax = 0
arr.each_with_index do |num, i|
  if num >= nmax
    nmax = num
  end
  if num >= max
    nmax = max
    max = num
    max_index = i
  end
end

arr.length.times do |i|
  p max_index == i ? nmax : max
end