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