#include <bits/stdc++.h>
using namespace std;
const int maxn = 400000 + 10;
int n, fa[2][maxn], ans[maxn], a[maxn];
pair<int, int> p[maxn];
int getfa(int k, int x) {
  return fa[k][x] == x ? x : fa[k][x] = getfa(k, fa[k][x]);
}
int main() {
  scanf("%d", &n);
  memset(ans, 0, sizeof ans);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), p[i] = make_pair(-a[i], i);
  sort(p + 1, p + 1 + n);
  for (int i = 0; i <= n + 1; i++) fa[0][i] = fa[1][i] = i;
  for (int i = 1; i <= n; i++) {
    int pos = p[i].second;
    fa[0][pos] = pos - 1;
    fa[1][pos] = pos + 1;
    int l = getfa(0, pos), r = getfa(1, pos);
    ans[max(0, r - l - 1)] = max(ans[max(0, r - l - 1)], a[pos]);
  }
  for (int i = n; i > 0; i--) ans[i] = max(ans[i], ans[i + 1]);
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
