fun main(args: Array<String>) {

    val n = readLine()!!.toInt()

    val a = (1..n).map { readLine()!!.toInt() }.toTypedArray()

    val initMax = a.max()!!

    for (i in 0 until n) {
        if (a[i] < initMax) {
            println(initMax)
        } else {
            val temp = a.copyOf()
            temp[i] = 0
            val tempMax = temp.max()!!
            println(tempMax)
        }
    }
}