#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), p(n), q(n);
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    p[i] = a[i];
  }
  sort(p.begin(), p.end());
  int max1 = p[n - 1];
  for (int i = 0; i < (n); i++) {
    q[i] = a[i];
    if (q[i] == max1) {
      q[i] = 0;
    }
  }
  sort(q.begin(), q.end());
  int max2 = q[n - 1];
  if (max2 == 0) {
    max2 = max1;
  }
  for (int i = 0; i < (n); i++) {
    if (a[i] == max1) {
      cout << max2 << endl;
    } else {
      cout << max1 << endl;
    }
  }
  return 0;
}
