#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
int a,b[210000],c[210000],d ;
cin>>a;
for(int i=0;i<a;i++){
  cin>>b[i];
  c[i]=b[i];
     }
  sort(c,c+a,greater<int>());
    for(int i=0;i<a;i++){
    if(b[i]==c[0]){cout<<c[1];}
    else cout<<c[0];
      cout<<endl;
    }
}
