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