object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val a = Seq.fill(n)(sc.nextInt)

  val (m1, m2) = a.foldLeft((0, 0)) {
    case ((m1, m2), v) =>
      if (v > m1) {
        (v, m1)
      } else if (v > m2) {
        (m1, v)
      } else {
        (m1, m2)
      }
  }

  for (i <- (0 to n - 1)) {
    if (a(i) == m1) {
      println(m2)
    } else {
      println(m1)
    }
  }
}