#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
using ll = long long;
int main(){ 
    ll n,b=0,c=0;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    vector<ll> d(n);
    rep(i,n) d[i]=a[i];
    sort(d.begin(),d.end());
    b=d[n-1];
    c=d[n-2];
    rep(i,n){
        if(a[i]!=b){
            cout<<b<<endl;
        }else{
            cout<<d<<endl;
        }
    }
    return 0;
}
