const main = (inputs) => {
  var N = inputs[0]-0;
  var arr = [];
  var max1 = 0;
  var max2 = 0;
  for(var i=1;i<=N;i++){
    var num = inputs[i]-0;
    arr.push(num);
    if(max1<num){
      max2 = max1;
      max1 = num;
    }else if(max2<num){
      max2 = num;
    }
  }
  for(var i=0;i<N;i++){
    console.log(arr[i] == max1? max2: max1);
  }
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));
