object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N = sc.nextInt
    val A = List.fill(N)(sc.nextInt).toVector
    sc.close()

    val set = A.toSet
    if (set.toList.length == 1) {
      A.foreach(println)
    } else {
      A.foreach(d => println(set.filter(_ != d).max))
    }
  }
}