#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n), tmp(n);
  for (int i = 0; i < (int)n; i++) {
    cin >> a[i];
    tmp[i] = a[i];
  }
  bool flg = true;
  for (int i = 0; i < (int)n - 1; i++) {
    if (a[i] != a[i + 1]) {
      flg = false;
      break;
    }
  }
  if (flg) {
    for (int i = 0; i < (int)n; i++) cout << a[0] << endl;
    return 0;
  }
  sort(tmp.begin(), tmp.end());
  ll amax = tmp[n - 1], asec;
  for (int i = n - 1; amax == tmp[i]; i--) {
    asec = tmp[i - 1];
  }
  for (int i = 0; i < (int)n; i++) {
    if (a[i] == amax)
      cout << asec << endl;
    else
      cout << amax << endl;
  }
  return 0;
}
