import java.util.*

fun main(args : Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    var maxIndex = 0;
    var secondMax = 0;
    var max = 0;
    (1..n).forEach{ i ->
        val v = sc.nextInt();
        if(v > max){ 
          secondMax = max; 
          max = v;
          maxIndex = i;
        }
        else if(v > secondMax){
          secondMax = v;
        }
    }
  
    (1..maxIndex-1).forEach{ i->
        println(max);
    }
    println(secondMax);
    (maxIndex+1..n).forEach{ i->
        println(max);
    }
}
