#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll A[200 * 1000 + 100];
ll L[200 * 1000 + 100];
ll R[200 * 1000 + 100];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  for (ll i = (1); i <= (N); i++) cin >> A[i];
  for (ll i = (2); i <= (N); i++) L[i] = max(L[i - 2], A[i - 1]);
  for (ll i = N - 1; i >= 1; i--) R[i] = max(R[i + 2], A[i + 1]);
  for (ll i = (1); i <= (N); i++) cout << max(L[i], R[i]) << endl;
}
