object Main extends App {
  val n = readInt
  val as = Range(0,n).map(t => (readInt, t)).sorted
  val biggest_i = as(n-1)._2
  val biggest = as(n-1)._1
  val second = as(n-2)._1
  println(Range(0,n).map(i=>if(i==biggest_i) second else biggest).mkString("\n"))
}