fun main(args: Array<String>) {
    val n = readInt()
    val a = List(n) { readInt() }
    val max = a.max()!!
    if (a.count { it == max } >= 2) {
        repeat(n - 1) {
            println(max)
        }
        return
    }

    val next = a.filter { it != max }.max()!!
    for (i in 0 until n) {
        when (a[i]) {
            max -> println(next)
            else -> println(max)
        }
    }
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()