import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val a = (1..n).map { sc.nextInt() }.toIntArray()

  val max = a.max()!!
  val second = a.sorted().reversed().drop(1).max()!!

  val ans = IntArray(n) { max }
  for (i in 0 until n) {
    if (a[i] == max) ans[i] = second
  }

  println(ans.joinToString("\n"))
}
