#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, max, n_max = 0;
  cin >> n;
  int a[n], b[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  max = b[n - 1];
  for (int i = n - 1; i >= 0; --i) {
    if (b[i] != max) {
      n_max = b[i];
      break;
    }
  }
  if (n_max == 0) n_max = max;
  for (int i = 0; i < n; ++i) {
    if (a[i] != max) {
      cout << max << "\n";
    } else {
      cout << n_max << "\n";
    }
  }
}
