#include <bits/stdc++.h>
using namespace std;
int pri[200050];
int que[200050];
int ans[200050];
int l[200050];
int r[200050];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &pri[i]);
      ans[i] = 0;
      l[i] = r[i] = 1;
    }
    int s = 1, e = 0;
    for (int i = 1; i <= n; i++) {
      while (s <= e && pri[que[e]] >= pri[i]) {
        l[i] = i - que[e] + l[que[e]];
        e--;
      }
      que[++e] = i;
    }
    s = 1, e = 0;
    for (int i = n; i >= 1; i--) {
      while (s <= e && pri[que[e]] >= pri[i]) {
        r[i] = r[que[e]] + que[e] - i;
        e--;
      }
      que[++e] = i;
    }
    for (int i = 1; i <= n; i++) {
      ans[l[i]] = max(ans[l[i]], pri[i]);
      ans[r[i]] = max(ans[r[i]], pri[i]);
      ans[r[i] + l[i] - 1] = max(ans[r[i] + l[i] - 1], pri[i]);
    }
    for (int i = n - 1; i >= 1; i--) {
      ans[i] = max(ans[i], ans[i + 1]);
    }
    for (int i = 1; i <= n; i++)
      if (i == 1)
        printf("%d", ans[i]);
      else
        printf(" %d", ans[i]);
    printf("\n");
  }
  return 0;
}
