#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;n>i;++i)
#define MOD 1000000007
using namespace std;
using ll=int64_t;
using pii=pair<int,int>;
using vi=vector<int>;
using VI=vector<ll>;
using vis=vector<string>;
using vvi=vector<vi>;
int gcd(int a,int b){
    if(a%b==0)
    return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
   return a*b/gcd(a,b);
}
int main(){
    ll n; cin>>n;
    VI a(n); rep(i,n) cin>>a[i];
    ll max_a,sec_a;
    set<ll> S;
    rep(i,n)
    S.insert(a[i]);
    
    max_a=*rbegin(S);
    if(S.size()==1){
        rep(i,n)
        cout<<max_a<<endl;
        return 0;
    }
    S.erase(*rbegin(S));
    sec_a=*rbegin(S);
    rep(i,n){
        if(a[i]==max_a) cout<<sec_a<<endl;
        else cout<<max_a<<endl;
    }
}