#include<bits/stdc++.h>
#define in(n) ll a[n];  for (i=0;i<n;i++)   cin>>a[i]
#define inb(n) ll b[n]; for (i=0;i<n;i++)   cin>>b[i]
#define op(n) for(i=0;i<n;i++)  cout<<a[i]<<" ";  cout<<endl;

#define ini ll n,i,j,k,l,m,o,p,s=0,su=0,s1=0,s2=0,d,x,y,z,r,q
#define te ll t;cin>>t;while(t--)

#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define min4(a,b,c,d) min(min3(a,b,c),d)
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define maxa(a,n) (*max_element(a,a+n))
#define maxv(v) (*max_element(v.begin(),v.end())
#define mina(a,n) (*min_element(a,a+n))
#define minv(v) (*min_element(v.begin(),v.end())
#define sot(v) sort(v.begin(),v.end())

#define ct(v,k) count(v.begin(),v.end(),k)
#define pb(a) push_back(a)




#define fo(j,n) for(i=j;i<n;i++)

#define itr(v) for(auto it=v.begin();it!=v.end();it++) 


#define fi it->first
#define sc it->second

using namespace std;

typedef long long int ll;
typedef long double db;

const ll  mod=(ll )1e9+7;

   ll gcd(ll a,ll b) { if(a%b==0) return b; return gcd(b,a%b); }
   ll ab(ll a){if(a<0) return -1*a;return a;}   
   ll cei(ll a,ll b){ if(a==0) return 0;return ((a-1)/b)+1;}  // postive values only
   ll flo(ll a,ll b){return a/b;}
   ll lc(ll a,ll b){return ((a*b)/gcd(a,b));}


ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m); t=(t*t)%m; if(b&1)t=(t*a)%m; return t;}



ll modInverse(ll a, ll m) { return power(a, m-2, m); }


void fastscan(ll &number)
{ 
    bool negative = false; 
     register ll c; number = 0; c = getchar(); 
    if (c=='-') 
    { 
        negative = true; 
        c = getchar(); 
    }
    
    for (; (c>47 && c<58); 
    c=getchar()) number = number *10 + c - 48; 
    if (negative)  number *= -1;   
}

inline vector<string> tokenize(string To_change,string delimiter)
{
    size_t pos = 0;
    string token;
    vector<string> changed;
    while ((pos = To_change.find(delimiter)) != string::npos) 
    {
        token = To_change.substr(0, pos);
        //cout << token << endl;
        changed.push_back(token);
        To_change.erase(0, pos + delimiter.length());
    }
    //cout << To_change << endl;
    changed.push_back(To_change);
    
    for(int i=0;i<(int)changed.size();i++)cout<<changed[i]<<endl;
    return changed;
}



/*
bool prime[1000001]; 
void Sieve(ll n){memset(prime, true, sizeof(prime));for (ll p=2; p*p<=n; p++) if (prime[p] == true) { for (ll i=p*p; i<=n; i += p)prime[i] = false;} prime[0]=false; prime[1]=false;}



ll fac[100001]; 
void ncrmodp(ll n, ll r, ll p){fac[0] = 1; for (ll i=1 ; i<=n; i++) fac[i] = fac[i-1]*i%p;} 
ll getncrmod(ll n,ll r,ll p){if (r==0) return 1;return (fac[n]* modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p; }
*/ 

// function to print the divisors
  


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ini;
    cin>>n;
    
    in(n);
    ll b[n];
    map<ll,ll> mp;
    fo(0,n)
    {
        b[i]=a[i];
        mp[a[i]]++;
    }
    
    m=*max_element(a,a+n);
    sort(b,b+n);
    j=b[n-2];
    fo(0,n)
    {
        if(a[i]<m)
        {
            cout<<m<<endl;
        }
        else 
        {
            cout<<j<<endl;
        }
    }
        
        
    return 0;
}

Measured memory_bytes: 12160