import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

fun <A : Comparable<A>> max(a: A, b: A) = if (a > b) a else b

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val A = IntArray(N) { sc.next().toInt() }
        val L = IntArray(N + 1)
        val R = IntArray(N + 1)
        var l = 0
        var r = 0
        for (i in 1..N) {
            l = max(l, A[i - 1])
            L[i] = l
            r = max(r, A[N - i])
            R[i] = r
        }
        for (i in 0 until N) {
            pw.println(max(L[i], R[N - i - 1]))
        }
    }
}
