fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val numbers = mutableListOf<Int>()
    for (i in 0 until n) {
        numbers.add(readLine()!!.toInt())
    }

    val maxNumber = numbers.fold(initial = 0, operation = { a, b -> Math.max(a,b)})
    val maxNumberCount = numbers.filter { it == maxNumber }.size

    val sortedNumbers = numbers.sorted()

    for (i in 0 until n) {
        if (numbers[i] < maxNumber) {
            println(maxNumber)
        } else {
            if (maxNumberCount > 1) {
                println(maxNumber)
            } else {
                println(sortedNumbers[1])
            }
        }
    }
}