fun main(array: Array<String>) {
    val n = readLine()!!.toInt()
    var list = mutableListOf<Int>()
    repeat(n) {
        var num = readLine()!!.toInt()
        list.add(num)
    }
    val copyList = list.toList().sorted()
    val max = copyList.max()
    val second = copyList[n-2]
    repeat(n) {
        if(list[it] == max) println(second)
        else println(max)
    }
}