fun main (args:Array<String>){
    val seqLen = readLine()!!.toInt()
    val seqList = mutableListOf<Int>(0, 0)
    val inputList = mutableListOf<Int>()
    var input = 0
    for(i in 1..seqLen){
        input = readLine()!!.toInt()
        inputList.add(input)
        if(seqList[0] < input) {
            seqList[0] = input
            continue
        }
        if(seqList[1] <= input){
            seqList[1] = input
        }
    }
    for(i in 0..seqLen-1){
        if(inputList[i] == seqList[0]){
            println(seqList[1])
        }
        else {
            println(seqList[0])
        }
    }
}