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