#include <bits/stdc++.h>
using namespace std;
long long num[200000] = {0};
long long sorted[200000] = {0};
int main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> num[i];
    sorted[i] = num[i];
  }
  sort(sorted, sorted + n);
  for (long long i = 0; i < n; i++) {
    if (num[i] == sorted[n - 1]) {
      int max = sorted[n - 1];
      for (long long ii = n - 1; ii >= 0; ii--) {
        if (max != sorted[i]) {
          cout << sorted[i] << endl;
          ii = -5;
        } else if (ii == 0) {
          cout << num[i] << endl;
        }
      }
    } else {
      cout << sorted[n - 1] << endl;
    }
  }
}
