object Main extends App {
  var a = readInt
  var b : Array[Int] = Array.tabulate(a)(i => (readInt))
  var max = b.max
  var p = 0
  for(i <- 0 until a ) {
    if(b(i)==max && p!=1) {
      p = 1
      b(i) = 0
      println(b.max)
    } else {
     println(max) 
    }
  }
}
