import java.util.Scanner

import scala.collection.immutable

object Main extends App {

  def read(): (Int, immutable.IndexedSeq[Int]) = {
    val sc: Scanner = new Scanner(System.in)
    val n = sc.nextInt
    val arr = (1 to n).map { _ =>
      sc.nextInt
    }
    sc.close()
    (n, arr)
  }

  def solve(): String = {
    val (n, arr) = read()
    val arrAndIndex = arr.zipWithIndex.sortBy(- _._1)
    val ans = for(i <- 0 until arr.length) yield {
      if(arrAndIndex(0)._2 == i) arrAndIndex(1)._1
      else arrAndIndex(0)._1
    }
    ans.mkString("\n")
  }
  println(solve)

}
