#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int a[2000000];
  int copy[2000000];
  int max, nmax;
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    copy[i] = a[i];
  }
  sort(a, a + n);
  max = a[n - 1];
  int temp = n - 2;
  while (a[temp] == max && temp != 0) temp--;
  nmax = a[temp];
  for (int i = 0; i < n; i++) {
    if (copy[i] == max)
      cout << nmax << endl;
    else
      cout << max << endl;
  }
  return 0;
}
