#include <bits/stdc++.h>
using namespace std;
int n;
int a[300010], b[300010], c[300010], ans[300010];
priority_queue<int> Q, D;
inline char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline void rea(int &x) {
  char c = nc();
  x = 0;
  for (; c > '9' || c < '0'; c = nc())
    ;
  for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = nc())
    ;
}
inline void Erase(int x) { D.push(x); }
inline int Top() {
  while (!D.empty() && D.top() == Q.top()) D.pop(), Q.pop();
  return Q.top();
}
int main() {
  rea(n);
  for (int i = 1; i <= n; i++) rea(a[i]), ans[n - 1] = max(ans[n - 1], a[i]);
  for (int i = 1; i < n; i++) b[i] = max(a[i], a[i + 1]);
  for (int i = 1; i < n - 1; i++) c[i] = min(a[i + 1], max(a[i], a[i + 2]));
  for (int i = 1; i < n; i++) Q.push(b[i]);
  int l = 1, r = n - 1;
  for (int i = 2; i <= n; i += 2) {
    ans[n - i] = Top();
    Erase(b[l]);
    Erase(b[r]);
    l++;
    r--;
  }
  while (!Q.empty()) Q.pop();
  while (!D.empty()) D.pop();
  for (int i = 1; i < n - 1; i++) Q.push(c[i]);
  l = 1;
  r = n - 2;
  for (int i = 3; i <= n; i += 2) {
    ans[n - i] = Top();
    Erase(c[l]);
    Erase(c[r]);
    l++;
    r--;
  }
  for (int i = 0; i < n; i++) printf("%d ", ans[i]);
  return 0;
}
