#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

//-----------------------------------------------

//------------------------------------------------

int main(){
  int n,m,mif;
  m=0;
  mif=0;
  int a[200010],b[200010];
  cin>>n;
  rep(i,0,n) {
    cin>>a[i];
    m=max(m,a[i]);
  }
  rep(i,0,n){
    if(a[i]!=m) cout<<m<<endl;
    else{
      rep(k,0,n){
        mif=max(mif,a[k]);
        if(k==i) break;
      }
      cout<<mif<<endl;
    }
  }
}
