#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  vll a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  vvll dp(n, vll(2));
  dp[1][0] = a[0];
  for (int i = 2; i < n; i++) {
    dp[i][0] = max(dp[i - 2][0], a[i - 1]);
  }
  dp[n - 2][0] = a[n - 1];
  for (int i = n - 3; i >= 0; i--) {
    dp[i][0] = max(dp[i + 2][0], a[i + 1]);
  }
  for (ll i = 0; i < n; i++) {
    cout << max(dp[i][0], dp[i][1]) << endl;
  }
  return 0;
}
