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