#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
 
int main() {
  ll n;
  cin >> n;
  vl v;
  inputv(v,n);
  ll mx=0,sec=0;
  rep(i,n){
    mx = max(mx,v[i]);
  }
  rep(i,n){
      if(v[i] < mx){
      sec = max(sec, v[i]);
    }
  }
  ll count=0;
  rep(i,n){
    if(v[i] == mx){
      count++;
    }
  }
  vl ans(n);
  if(count == 1){
  rep(i,n){
      if(v[i] == mx){
        ans[i] = sec;
      } else {
        ans[i] = mx;
      }
  }
  }
  if(count > 1){
    ans[i] = mx;
  }
  rep(i,n){
    cout << ans[i] << endl;
  }
 return 0;
}
