function Main(input) {
  input = input.split("\n");
  var length = parseInt(input[0]);
  input.shift();
  for(var i = 0; i < input.length; i++){
    input[i] = parseInt(input[i]);
  }
  var tmpInput = JSON.parse(JSON.stringify(input));
  tmpInput.sort(function(a,b){
  	return b - a;
  });
  var max1 = tmpInput[0];
  var max2 = tmpInput[1];
  var max1Index = input.indexOf(max1);
  //console.log("max1:" + max1Index);
  if(max2 == max1){
     //最大値が2回以上出てきている場合は、最大値をN回出力して終わり
    var output = "";
    for(var i = 0; i < length; i++){
      if(i == 0){
         output += max1;
      }else{
         output += "\n" + max1;
      }
    }
    console.log(output);
    return;
  }else{
    var output = "";
    for(var i = 0; i < length; i++){
      if(i != max1Index){
        if(i == 0){
           output == max1;
        }else{
           output += "\n" + max1;
        }
      }else{
        if(i == 0){
           output == max2;
        }else{
           output += "\n" + max2;
        }
      }
    }
    console.log(output);
    return;
  }
  
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));
