import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().toInt
  var a = Array.fill(n)(0)

  (0 to n - 1).foreach {i =>
    a(i) = StdIn.readLine().toInt
  }

  val f = a.max
  val fcount  = a.filter(_ == f).length
  val sarray  = a.filter(_ != f)
  val s = if (sarray.isEmpty) f else sarray.max

  a.foreach { i =>
    if (i == f && fcount > 1) {
      println(f)
    } else if (i == f && fcount == 1) {
      println(s)
    } else {
      println(f)
    }
  }
}
  

