#include <bits/stdc++.h>
using namespace std;
constexpr auto inf = 1e9;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n, -1);
  for (auto& x : a) {
    cin >> x;
  }
  int maxnum = *max_element((a).begin(), (a).end());
  vector<int> tmp(n);
  tmp = a;
  sort((tmp).begin(), (tmp).end());
  for (int i = 0; i < n; i++) {
    int ans = 0;
    if (tmp[n - 1] == tmp[n - 2]) {
      ans = a[n - 1];
    } else {
      if (maxnum == a[i]) {
        ans = tmp[n - 2];
      } else {
        ans = a[n - 1];
      }
    }
    cout << ans << endl;
  }
  return 0;
}
