import java.util.Scanner

object Main extends App{
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val al = List.fill(n)(sc.nextInt)

  val (max, semiMax) =
    al.foldLeft((0, 0)){case ((m, sm), a) =>
      if (a >= m) (a,m)
      else if(a >= sm) (m, a)
      else (m, sm)
    }

  al.foreach { a =>
    println {
      if (a == max) semiMax
      else max
    }
  }
}
