#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> v(n);
  cin >> n;
  int mv = 0;
  int mv_c = 0;
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
    if (mv == v.at(i)) {
      mv_c++;
    } else if (mv < v.at(i)) {
      mv = v.at(i);
      mv_c = 1;
    }
  }
  if (mv_c >= 2) {
    for (int i = 0; i < n; i++) {
      cout << mv << endl;
    }
  } else {
    vector<int> v2(n);
    copy(v.begin(), v.end(), back_inserter(v2));
    sort(v2.begin(), v2.end(), greater<int>());
    int mv_next = v2.at(1);
    for (int i = 0; i < n; i++) {
      if (v.at(i) == mv) {
        cout << mv_next << endl;
      } else {
        cout << mv << endl;
      }
    }
  }
}
