#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2e5;
int n, ans[Maxn];
pair<int, int> a[Maxn];
int par[Maxn], size[Maxn];
bool good[Maxn];
void Init(void) {
  for (int i = 0; i < n; ++i) {
    par[i] = i;
    size[i] = 1;
  }
}
int Find(int i) { return i == par[i] ? i : par[i] = Find(par[i]); }
void Unite(int i, int j) {
  i = Find(i);
  j = Find(j);
  if (i != j) {
    par[i] = j;
    size[j] += size[i];
  }
}
int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i].first);
    a[i].second = i;
  }
  sort(a, a + n);
  Init();
  int len = 0;
  for (int i = n - 1; i >= 0; --i) {
    int j = a[i].second;
    good[j] = true;
    if (j > 0 && good[j - 1]) {
      Unite(j, j - 1);
    }
    if (j < n - 1 && good[j + 1]) {
      Unite(j, j + 1);
    }
    len = max(len, size[Find(j)]) - 1;
    ans[len] = max(ans[len], a[i].first);
  }
  for (int i = n - 2; i >= 0; --i) {
    ans[i] = max(ans[i], ans[i + 1]);
  }
  for (int i = 0; i < n; ++i) {
    printf("%d ", ans[i]);
  }
  putchar('\n');
  return 0;
}
