#include <bits/stdc++.h>
using namespace std;
long long n, dsu[200005], siz[200005], vis[200005], ans[200005];
struct bear {
  long long u, h;
  bool operator<(const bear b) const { return h > b.h; }
} a[200005];
long long find_(long long x) {
  return dsu[x] == x ? x : dsu[x] = find_(dsu[x]);
}
void union_(long long x, long long y) {
  long long fx = find_(x), fy = find_(y);
  if (fx != fy) dsu[fx] = fy, siz[fy] += siz[fx];
}
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; cin >> a[i].h, i++)
    ;
  for (long long i = 1; i <= n; i++) dsu[i] = i, siz[i] = 1, a[i].u = i;
  sort(a + 1, a + 1 + n);
  long long p = 1;
  for (long long i = 1; i <= n; i++) {
    vis[a[i].u] = 1;
    if (vis[a[i].u - 1]) union_(a[i].u - 1, a[i].u);
    if (vis[a[i].u + 1]) union_(a[i].u + 1, a[i].u);
    for (; p <= siz[find_(a[i].u)]; p++) ans[p] = a[i].h;
  }
  for (long long i = 1; i <= n; i++) cout << ans[i] << ' ';
  return puts(""), 0;
}
