N = gets.to_i
A = N.times.map{gets.to_i}

max = A.max
second_max = A.sort[-2]
max_cnt = A.count(max)

if max_cnt >= 2
  A.each do |a|
    puts max
  end
  exit
end

A.each do |a|
  if a == max
    puts second_max
  else
    puts max
  end
end
