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_1 = a.max()
    val s = a.filter{ it == m_1 }.size
    if (s >= 2) for (i in 0 until n) println(m_1)
    if (s == 1) {
        val idx = a.indexOf(m_1)
        var b = a.toMutableList()
        b.removeAt(idx)
        val m_2 = b.max()
        for (i in 0 until n) {
            if (i == idx) println(m_2) else println(m_1)
        }
    }
}
