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().reversed()

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