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