#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(3);
  int n;
  cin >> n;
  int a[n];
  int maxt = 0;
  bool bb = 0;
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    if (maxt == a[i]) bb = 1;
    maxt = max(maxt, a[i]);
  }
  for (int i = 0; i < (n); i++) {
    if (bb)
      cout << maxt << endl;
    else if (a[i] != maxt)
      cout << maxt << endl;
    else {
      int c = 0;
      for (int i = 0; i < (n); i++) {
        if (a[i] != maxt) c = max(c, a[i]);
      }
      cout << c << endl;
    }
  }
}
