#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 55;
signed main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) cin >> A[i];
  vector<ll> S1(N, -INF);
  vector<ll> S2(N, -INF);
  for (ll i = 0; i < N; i++) S1[i] = max(S1[i], A[i]);
  for (ll i = N - 1; i >= 0; i--) S2[i] = max(S2[i], A[i]);
  for (ll i = 0; i < N; i++) {
    ll ret = -INF;
    if (i > 0) ret = max(ret, S1[i - 1]);
    if (i < N - 1) ret = max(ret, S2[i + 1]);
    cout << ret << endl;
  }
  return 0;
}
