object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val a = Array.fill(n)(sc.nextInt)
  val sorted = a.sorted
  val last1 = sorted(n-1)
  val last2 = sorted(n-2)
  a.foreach(i => println(calc(i)))
  
  def calc(i: Int): Int = if (i == last1) last2 else last1
}