#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3 * 1e5 + 4;
int n, a[MAXN], a1[MAXN], a2[MAXN], sol[MAXN], pom = 0, p = 0, maxi = 0;
multiset<int> b[2];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) maxi = max(a[i], maxi);
  a1[0] = a[0];
  a1[n - 1] = a[n - 1];
  for (int i = 1; i < n - 1; i++) a1[i] = min(a[i], max(a[i - 1], a[i + 1]));
  for (int i = 0; i < n - 1; i++) a2[i] = max(a[i], a[i + 1]);
  for (int i = 0; i < n; i++) b[0].insert(-a1[i]);
  for (int i = 0; i < n - 1; i++) b[1].insert(-a2[i]);
  for (int i = n - 1; i >= 0; i--) {
    if (!p) {
      sol[i] = -(*b[0].begin());
      if (i == 0) continue;
      b[0].erase(b[0].lower_bound(-a1[n - pom / 2 - 1]));
      b[0].erase(b[0].lower_bound(-a1[pom / 2]));
    } else {
      sol[i] = -(*b[1].begin());
      if (i == 0) continue;
      b[1].erase(b[1].lower_bound(-a2[n - pom / 2 - 2]));
      b[1].erase(b[1].lower_bound(-a2[pom / 2]));
    }
    p = (p + 1) % 2;
    pom++;
  }
  sol[n - 1] = maxi;
  for (int i = 0; i < n; i++) cout << sol[i] << " ";
  return 0;
}
