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