n=gets.to_i
a=[]
max=0
(0..n-1).each do |i|
  a[i]=gets.to_i
end
max=a.max
idx=a.index(max)
a.sort!
(0..n-1).each do |i|
  if a[-2]==a[-1]
    puts a[-1]
  elsif i == idx
    puts a[-2]
  else
    puts a[-1]
  end
end