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