#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, a;
  vector<int> as;
  cin >> n;
  for (int i = 0, i_len = (n); i < i_len; i++) {
    cin >> a;
    as.push_back(a);
  }
  set<int> vset;
  for (const int i : as) vset.insert(i);
  vector<int> vector<string>(vset.begin(), vset.end());
  sort((vector<string>).begin(), (vector<string>).end());
  int ma1 = vector<string>[vector<string>.size() - 1];
  int ma2 = vector<string>[vector<string>.size() - 2];
  if (count((as).begin(), (as).end(), ma1) > 2) {
    for (int i = 0, i_len = (as.size()); i < i_len; i++) {
      cout << ma1 << endl;
    }
  } else {
    for (const int i : as) {
      if (i == ma1) {
        cout << ma2 << endl;
      } else {
        cout << ma1 << endl;
      }
    }
  }
  return 0;
}
