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