import java.io.PrintWriter
import kotlin.collections.*

val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

    fun func() {
        val n = nextInt()
        val a = List<Int>(n){nextInt()}
        val a_s = a.map{e-> e}.sortedDescending()
      	for(i in 0 until n){
          if(a[i]==a_s[0]){println(a_s[1])}
          else println(a_s[0])
        }
    }

// 入力取得
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

fun println(value : Any) {
    pw.println(value)
}
