#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    ll n;
    cin>>n;
    ll ai;
    ll aii=0;
    ll max=0;
    vector<ll> k;
    rep(i,n){
        cin>>ai;
        k.pb(ai);
        if(ai>max){
            max=ai;
            aii=i;
        }
    }
    sort(k.begin(),k.end(),greater<ll>[]);

    rep(i,n){
        if(i!=aii)cout<<k[0]<<endl;
        else cout<<k[1]<<endl;
    }
    return 0;
}