fun main(args: Array<String>){
    val n = readLine()!!.toInt()
    var a = arrayListOf<Int>()
    for (i in 0 until n){
        a.add(readLine()!!.toInt())
    }
    val m = a.max()
    for (i in 0 until n) {
        if (a[i] != m) {
            println(m)
        } else {
            var b = a
            b.removeAt(i)
            println(b.max())
        }
    }
}