#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int a[n];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ma = 0;
  for (int i = 0; i < n; i++) {
    ma = max(ma, a[i]);
  }
  int ne = 0;
  int frag = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != ma) {
      ne = max(ne, a[i]);
    } else {
      frag++;
    }
  }
  for (int i = 0; i < n; i++) {
    if (ma == a[i]) {
      if (frag > 1) {
        cout << ma << endl;
      } else {
        cout << ne << endl;
      }
    } else {
      cout << ma << endl;
    }
  }
  return 0;
}
