#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 100000 + 100;
struct node {
  int x;
  int cur;
} a[maxn];
int ant[maxn];
int lef[maxn];
int righ[maxn];
bool cmp(node u, node v) { return u.x > v.x; }
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i].x);
      a[i].cur = i + 1;
    }
    sort(a, a + n, cmp);
    memset(lef, 0, sizeof(lef));
    memset(righ, 0, sizeof(righ));
    memset(ant, 0, sizeof(ant));
    for (int i = 0; i < n; i++) {
      int cwt = 1;
      int v = a[i].cur;
      if (v - 1 >= 1) {
        lef[v] = lef[v - 1] + 1;
      } else
        lef[v] = 1;
      if (v + 1 <= n) {
        righ[v] = righ[v + 1] + 1;
      } else
        righ[v] = 1;
      cwt = righ[v] + lef[v] - 1;
      if (v - 1 >= 1) righ[v - lef[v] + 1] = max(righ[v - lef[v] + 1], cwt);
      if (v + 1 <= n) lef[v + righ[v] - 1] = max(lef[v + righ[v] - 1], cwt);
      ant[cwt] = max(ant[cwt], a[i].x);
    }
    int cwt = 0;
    for (int i = n; i > 0; i--) {
      cwt = max(cwt, ant[i]);
      ant[i] = cwt;
    }
    for (int i = 1; i < n; i++) printf("%d ", ant[i]);
    printf("%d\n", ant[n]);
  }
  return 0;
}
