fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = Array(N) {
        readLine()!!.toInt()
    }
    val AC = A.copyOf().sortedDescending()

    for (i in A.indices) {
        if (A[i] == AC.first()) {
            println(AC[1])
        } else {
            println(AC.first())
        }
    }
}

