function Main(input){
  inputs=input.split("\n");
  numbers=inputs.filter((x,i)=>i!==0&&x!="").map(x=>parseInt(x));

  count=parseInt(inputs[0]);
  countArray=[...Array(count)];

  max1=0;
  max2=0;
  countArray.map((_,i)=>{
    max2=(numbers[i]>max2?numbers[i]:max2);
    if(max2>max1){
      [max2,max1]=[max1,max2];
    }
  });

  countArray.map((_,i)=>{
    console.log(numbers[i]!=max1?max1:max2);
  });
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));
