#include <bits/stdc++>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
  int n;cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int h;h=0;
  vector<int> s=a;
  sort(s.begin(),s.end());
  reverse(s.begin(),s.end());
  rep(i,n){
    rep(j,n){
      h=max(h,a[j]);
    }
    if(h==a[i]){
      cout << s[1] << endl;
    }
    else{
      cout << h << endl;
    }
  }
}
  