object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N = sc.nextInt
  val numbers = List.fill(N)(sc.nextInt)
  val highest = numbers.sorted.reverse(0)
  val secondHighest = numbers.sorted.reverse(1)

  for(i <- 0 until N) {
    if (numbers(i) == highest) println(highest)
    else println(secondHighest)
  }

}