n = gets.to_i
as = []
for i in 0..n-1
  as[i]=gets.to_i
end

max=as.max
asc = as.clone
asc.delete_if{|i|i==max}
max_2=asc.max
s = asc.size

for i in 0..n-1
  puts max if s!=n-1
  puts max if as[i]!=max && s==n-1
  puts max_2 if as[i]==max && s==n-1
end
