object Main extends App {
  val n = scala.io.StdIn.readInt
  val a = Array.tabulate(n)(i => scala.io.StdIn.readInt)
  var b = a.sorted.reverse
  var m0 = b(0)
  var m1 = b(1)
  for(i <- 0 until n) {
    if(a(i) == m0) {
      println(m1)
    } else {
      println(m0)
    }
  }
}
