
fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val numberList = (1..n).map { readLine()!!.toInt() }

    var max = 0
    var second = 0
    for(num in numberList) {
        if(num >= max) {
            second = max
            max = num
        } else if(num >= second) {
            second = num
        }
    }

    for(num in numberList) {
        if(num == max) {
            println(second)
        } else {
            println(max)
        }
    }
}
