fun main(args: Array<String>) {
    val line_num = readLine()!!.toInt()
    val A = List(line_num){
        readLine()!!.toInt()
    }
    val (max0,max1) = A.sortedDescending().take(2)

    val list = mutableListOf<Int>()

    for (a in A)
        list.add(if(max0 != a) max0 else max1)

    println(list.joinToString("\n"))
}