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