N = gets.to_i
a = 0
ar = []
max = 0
max_index = 0
max_dup_flag = false
N.times do |i|
  a = gets.to_i
  ar << a
  if max < a
    max_index = i
    max_dup_flag = false
    max = a
  elsif max == a
    max_dup_flag = true
  end
end

if max_dup_flag
  N.times do |i|
    puts max
  end
else
  N.times do |i|
    if i == max_index
      puts ar.sort[-2]
    else
      puts max
    end
  end
end
