fun main(args: Array<String>) = println(run {
    val n = readLine()!!.toInt()
    val a = (1..n).map { readLine()!!.toInt() }

    val max1 = a.sortedDescending()[0]
    val max2 = a.sortedDescending()[1]
    a.map { if (it==max1) max2 else max1 }.joinToString("\n") { it.toString() }
})