fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun main(args: Array<String>) {
    val N = readInt()
    val A = Array(N) { readInt() }
    val maxA = mutableListOf(A[0], A[1]).apply { sortDescending() }
    for (i in 2 until A.size) {
        if (A[i] > maxA[0]) {
            maxA[1] = maxA[0]
            maxA[0] = A[i]
        } else if (A[i] > maxA[1]) {
            maxA[1] = A[i]
        }
    }

    for (i in A.indices) {
        println(
            if (A[i] != maxA[0]) {
                maxA[0]
            } else {
                maxA[1]
            }
        )
    }
}