fun main(args:Array<String>) {
    val itemCount = readLine()!!.toInt()
    val items = (1..itemCount).map { readLine()!!.toInt() }
    val max = items.max()!!
    val maxCount = items.count { it == max }

    items.forEach {
        if(it == max && maxCount == 1) {
            println(items.filter { it != max }.max()            )
        } else {
            println(max)
        }
    }

}
