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