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

max_idx = -1
max_val = -1
second_val = -1
A.each_with_index do |a, idx|
  if a > max_val
    second_val = max_val
    max_val = a
    max_idx = idx
  elsif a == max_val || a > second_val
    second_val = a
  end
end

N.times do |idx|
  if idx == max_idx
    puts second_val
  else
    puts max_val
  end
end
