#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  long long a[t], b[t];
  for (int i = 0; i < t; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a, a + t);
  long long m = a[t - 1], l = a[t - 2];
  for (int i = 0; i < t; i++) {
    if (b[i] == m)
      cout << l << "\n";
    else
      cout << m << "\n";
  }
  return 0;
}
