#include <bits/stdc++.h>
using namespace std;
const int MN = 200111;
int n, a[MN], l[MN], r[MN], st[MN], top;
int res[MN];
int main() {
  while (scanf("%d", &n) == 1) {
    for (int i = (1), _b = (n); i <= _b; i++) scanf("%d", &a[i]);
    top = 0;
    st[0] = 0;
    a[0] = 0;
    for (int i = (1), _b = (n); i <= _b; i++) {
      while (top && a[st[top]] >= a[i]) --top;
      l[i] = st[top] + 1;
      st[++top] = i;
    }
    top = 0;
    st[0] = n + 1;
    a[n + 1] = 0;
    for (int i = (n), _b = (1); i >= _b; i--) {
      while (top && a[st[top]] >= a[i]) --top;
      r[i] = st[top] - 1;
      st[++top] = i;
    }
    memset(res, 0, sizeof res);
    for (int i = (1), _b = (n); i <= _b; i++) {
      int len = r[i] - l[i] + 1;
      res[len] = max(res[len], a[i]);
    }
    for (int i = (n - 1), _b = (1); i >= _b; i--)
      res[i] = max(res[i], res[i + 1]);
    for (int i = (1), _b = (n); i <= _b; i++) printf("%d ", res[i]);
    puts("");
  }
  return 0;
}
