#include <bits/stdc++.h>
template <class T>
inline T chmax(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T>
inline T chmin(T& a, const T b) {
  return a = (a > b) ? b : a;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = acos(-1);
using namespace std;
struct INIT {
  INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  }
} INIT;
signed main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < ll(N); ++i) cin >> A[i];
  ll MAX = 0;
  for (ll i = 0; i < ll(N); ++i) chmax(MAX, A[i]);
  ll cnt = 0;
  ll second = 0;
  for (ll i = 0; i < ll(N); ++i) {
    if (A[i] == MAX)
      cnt++;
    else
      chmax(second, A[i]);
  }
  if (cnt == 2) {
    for (ll i = 0; i < ll(N); ++i) cout << MAX << "\n";
  } else {
    for (ll i = 0; i < ll(N); ++i) {
      if (A[i] != MAX)
        cout << MAX << "\n";
      else
        cout << second << "\n";
    }
  }
  return 0;
}
