fun main(args:Array<String>) {
    val N = readLine()!!.toInt()
    var aList = mutableListOf<Int>()
    var nextMaxA = 0;
    for (i in 1..N) {
        aList.add(readLine()!!.toInt())
    }
    var sortedList = aList.sortedDescending()
    for (i in 0..N-1) {
        if (aList[i] == sortedList[0]) {
            println(sortedList[1])
        } else {
            println(sortedList[0])
        }
    }

}
