#include <bits/stdc++.h>
#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];
  
  vector<int> s = a;
  
  sort(s.rbegin(),s.rend());
  
  rep(i,n){
    if(a[i]==s[0]){
      cout << s[1] <<endl;
    }else cout << s[0] <<endl;
  }
}
