fun main(args: Array<String>) {
    val n = readLine()!!.split(" ").map { it.toInt() }[0]
    val aArray = Array(n){ 0 }
    for (i in 0 until n) {
        val a = readLine()!!.split(" ").map { it.toInt() }[0]
        aArray[i] = a
    }
    val max = aArray.max()
    val index = aArray.indexOf(max)
    val removeMaxArray = aArray.toMutableList()
    removeMaxArray.removeAt(index)
    val secondMax = removeMaxArray.max()
    for (i in 0 until n){
        if (aArray[i] != max){
            println(max)
        } else {
            println(secondMax)
        }
    }
}