#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n], b[n];
  set<long long> s;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  long long max1 = b[n - 1];
  long long max2 = b[n - 2];
  for (long long i = 0; i < n; i++) s.insert(b[i]);
  if (s.size() > 1) {
    for (auto it = s.begin(); it != s.end(); it++) {
      if (*it != max1) max2 = *it;
    }
  }
  for (long long i = 0; i < n; i++) {
    if (a[i] != max1)
      cout << max1 << endl;
    else
      cout << max2 << endl;
  }
  return 0;
}
