#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];
  }
  auto m = max_element(a.begin(), a.end());
  int m2 = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] != *m && a[i] > m2) {
      m2 = a[i];
    }
  }
  if (m2 == 0) m2 = *m;
  for (int i = 0; i < n; ++i) {
    if (a[i] != *m)
      cout << *m << endl;
    else
      cout << m2 << endl;
  }
  return 0;
}
