#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, mx, p, t;
  mx = -1;
  t = -1;
  cin >> n;
  map<int, int> a;
  for (int i = 0; i < n; i++) {
    cin >> m;
    auto itr = a.find(m);
    if (itr != a.end()) {
      a[itr->first] += 1;
    } else {
      a[m] = 1;
    }
    if (mx < m) {
      mx = m;
      p = i;
    } else if (t < m) {
      t = m;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[m] > 1) {
      cout << mx << endl;
    } else {
      if (i != p) {
        cout << mx << endl;
      } else {
        cout << t << endl;
      }
    }
  }
  return 0;
}
