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 farray  = a.filter(_ != f)
  val s = if (farray.isEmpty) f else farray.max

  a.map {v =>
    if (v == f) s else f
  }.foreach { i =>
    println(i)
  }
}
  

