import java.lang.StringBuilder

fun main(args: Array<String>) {
    val length = readLine()!!.toInt()
    val sequence = mutableListOf<Int>()
    repeat(length) {
        sequence.add(readLine()!!.toInt())
    }

    val ans = StringBuilder()
    val max = sequence.max()
    if (sequence.count { it == max } >= 2) {
        repeat(length) {
            ans.append("$max\r\n")
        }
    } else {
        val next = sequence.filterNot { it == max }.max()
        for (i in sequence) {
            when (i) {
                max -> ans.append("$next\r\n")
                else -> ans.append("$max\r\n")
            }
        }
    }
    print(ans)
}
