N = gets.to_i
max = gets.to_i
max_2 = 0
array = [max]
(N-1).times do
  res = gets.to_i
  if res >= max
    max_2 = max
    max = res
  elsif res > max_2
    max_2 = res
  end
  array.push(res)
end

N.times do |i|
  if array[i] == max
    puts max_2
  else
    puts max
  end
end
