#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;
priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;
pair<int, int> vec[200001];
int p[200000];
char visit[200000];
int zmrl[200000];
int ans[200001];
int find(int a) {
  if (p[a] == -1) return a;
  return p[a] = find(p[a]);
}
void merge(int a, int b) {
  a = find(a);
  b = find(b);
  if (a == b) return;
  zmrl[a] += zmrl[b];
  p[b] = a;
}
int main() {
  memset(p, -1, sizeof(p));
  int n;
  scanf("%d", &n);
  fill(zmrl, zmrl + n, 1);
  for (int i = 0; i < n; i++) {
    scanf("%d", &vec[i].first);
    vec[i].second = i;
  }
  vec[n].first = -1;
  sort(vec, vec + n, greater<pair<int, int> >());
  int now = 0, mav = 0;
  int pre = vec[0].first, prei = 0;
  for (int i = 1; i <= n; i++) {
    if (pre == vec[i].first) continue;
    while (prei < i) {
      visit[vec[prei].second]++;
      if (vec[prei].second && visit[vec[prei].second - 1])
        merge(vec[prei].second, vec[prei].second - 1);
      if (vec[prei].second != n - 1 && visit[vec[prei].second + 1])
        merge(vec[prei].second, vec[prei].second + 1);
      mav = max(mav, zmrl[find(vec[prei].second)]);
      prei++;
    }
    while (now < mav) {
      now++;
      ans[now] = vec[i - 1].first;
    }
  }
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}
