#include <bits/stdc++.h>
using namespace std;
int ml, n, f[250000], ans[250000], l[250000];
struct data {
  int p, v;
} a[250000], b[250000];
bool cmp(data a, data b) { return a.v > b.v; }
int gf(int x) { return x == f[x] ? x : f[x] = gf(f[x]); }
void Add(int x, int k) {
  int p = a[x].p + k;
  if (!p || p > n || b[p].v < a[x].v) return;
  int f1 = gf(a[x].p), f2 = gf(p);
  if (f1 != f2) f[f1] = f2, l[f2] += l[f1], ml = max(ml, l[f2]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i].v), b[i].v = a[i].v, a[i].p = i, f[i] = i, l[i] = 1;
  sort(a + 1, a + 1 + n, cmp);
  int l = 1, nl = 0;
  ml = 1;
  while (l <= n) {
    Add(l, 1), Add(l, -1);
    while (a[l + 1].v == a[l].v) ++l, Add(l, 1), Add(l, -1);
    while (nl + 1 <= ml) ans[++nl] = a[l].v;
    l++;
  }
  for (int i = nl + 1; i <= n; i++) ans[i] = a[n].v;
  for (int i = 1; i < n; i++) printf("%d ", ans[i]);
  printf("%d\n", ans[n]);
  return 0;
}
