#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a.push_back(x);
  }
  vector<long long>::iterator p;
  p = max_element(a.begin(), a.end());
  long long m = *(max_element(a.begin(), a.end()));
  for (long long i = 0; i < n; i++) {
    if (a[i] != m)
      cout << m << endl;
    else {
      *p = 0;
      cout << *(max_element(a.begin(), a.end())) << endl;
    }
  }
  return 0;
}
