fun main(args: Array<String>) {
    val N = nextInt()
    val A = Array(N) { nextInt() }
    val B = A.sortedDescending()
    A.forEach {
        val ans = if (it == B[0]) B[1] else B[0]
        println(ans)
    }
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())