#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int r[N], p[N], v[N], n;
int mx[N], mn[N], cnt[N];
pair<int, int> a[N];
bool used[N];
int ans[N];
void init() {
  for (int i = 0; i < n; i++) {
    r[i] = 0;
    p[i] = i;
    mn[i] = mx[i] = v[i];
    cnt[i] = 1;
  }
}
int root(int x) { return (x == p[x] ? x : p[x] = root(p[x])); }
void join(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y) return;
  if (r[x] < r[y]) swap(x, y);
  p[y] = x;
  r[x] += (r[x] == r[y]);
  mn[x] = min(mn[x], mn[y]);
  mx[x] = max(mx[x], mx[y]);
  cnt[x] += cnt[y];
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
    a[i] = make_pair(-v[i], i);
  }
  sort(a, a + n);
  init();
  for (int i = 0; i < n; i++) {
    int pos = a[i].second, val = a[i].first;
    used[pos] = true;
    if (pos > 0 && used[pos - 1]) {
      join(pos, pos - 1);
    }
    if (pos + 1 < n && used[pos + 1]) {
      join(pos, pos + 1);
    }
    pos = root(pos);
    ans[cnt[pos]] = max(ans[cnt[pos]], mn[pos]);
  }
  int p = ans[n];
  for (int i = n - 1; i >= 1; i--) {
    p = max(ans[i], p);
    ans[i] = p;
  }
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
