fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val numberList = (1..n).map { readLine()!!.toInt() }
    val sorted = numberList.sortedDescending()
    numberList.forEach {
        if(it == sorted.first()) {
            println(sorted[1])
        } else {
            println(sorted.first())
        }
    }
}