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