import java.util.Scanner

fun main() {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val leftmax = IntArray(n)
    val rightmax = IntArray(n)
    val num = IntArray(n)
    leftmax[0] = 0
    rightmax[n - 1] = 0
    for (i in 0 until n) {
        num[i] = sc.nextInt()
    }
    for (i in 1 until n) {
        leftmax[i] = Math.max(leftmax[i - 1], num[i - 1])
    }
    for (i in n - 1 downTo 1) {
        rightmax[i - 1] = Math.max(rightmax[i], num[i])
    }
    for (i in 0 until n) {
        println(Math.max(leftmax[i], rightmax[i]))
    }
}
