object Main extends App {
  val n = io.StdIn.readInt
  val as = for (_ <- 1 to n) yield io.StdIn.readInt
  
  val sorted = as.sorted.reverse.take(2)
  val max_first = sorted(0)
  val max_second = sorted(1)

  for (a <- as) {
    if (a == max_first) println(max_second)
    else println(max_first)
  }
}