#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, amax = 0, asec = 0;
  bool same = false;
  cin >> n;
  long long a[200010];
  for (long long i = (long long)0; i < (long long)n; i++) {
    cin >> a[i];
    if (amax == a[i]) {
      same = true;
    } else if (a[i] > amax) {
      asec = amax;
      amax = a[i];
    } else if (a[i] < amax) {
      asec = max(asec, a[i]);
    }
  }
  for (long long i = (long long)0; i < (long long)n; i++) {
    if (same) {
      cout << amax << endl;
      ;
    } else {
      if (a[i] == amax) {
        cout << asec << endl;
        ;
      } else {
        cout << amax << endl;
        ;
      }
    }
  }
  return 0;
}
