#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, mx = 0, mx2 = 0, cnt;
  cin >> n;
  vector<int> a(n, 0);
  for (int(i) = 0; i < (n); i++) {
    cin >> a.at(i);
    if (a.at(i) > mx) {
      mx2 = mx;
      mx = a.at(i);
      cnt = 1;
    } else if (a.at(i) == mx) {
      cnt++;
    } else if (mx2 < a.at(i) && a.at(i) < mx) {
      mx2 = a.at(i);
    }
  }
  if (cnt == 2)
    for (int(i) = 0; i < (n); i++) cout << mx << endl;
  else
    for (int(i) = 0; i < (n); i++) {
      if (a.at(i) == mx)
        cout << mx2 << endl;
      else
        cout << mx << endl;
    }
}
