fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val A = IntArray(N)
    (0 until N).forEach {
        A[it] = readLine()!!.toInt()
    }

    val sotrtedA = A.sortedDescending()

    A.forEach {
        val max = sotrtedA[0]
        val secondMax = sotrtedA[1]

        if (it != max) {
            println(max)
        } else {
            println(secondMax)
        }
    }
}