fun main(args: Array<String>)
{
    val n = readInt()
    val a = mutableListOf<Int>()
    for (i in 1..n) {
        a.add(readInt())
    }

    val sorted = mutableListOf<Int>()
    for(i in 1..n) {
        sorted.add(a[i-1])
    }
    sorted.sortDescending()
    val first = sorted[0]
    val second = sorted[1]

    for(i in 1..n) {
        println(if (a[i-1] == first) second else first )
    }
}


// Read an integer
// Usage: val a = readInt()
private fun readInt() = readLine()!!.toInt()

// Read N integers separated by " "
// Usage: val (a, b, c) = readNInts()
private fun readNInts() = readLine()!!.split(" ").map(String::toInt)

// Read a string
// Usage: val a = readString()
private fun readString() = readLine()!!
