#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
vector<pair<int, int> > v;
int ans[N], tg[N], p[N], ok[N];
int find(int u) {
  if (p[u] != p[p[u]]) return p[u] = find(p[u]);
  return p[u];
}
void merge(int a, int b) {
  int pa = find(a), pb = find(b);
  if (pa != pb) {
    p[pa] = pb;
    tg[pb] += tg[pa];
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    p[i] = i;
    tg[i] = 1;
    int x;
    cin >> x;
    v.push_back(make_pair(x, i));
  }
  sort(v.rbegin(), v.rend());
  int cur = 0, prev = 1;
  for (int i = 0; i < (int)v.size(); ++i) {
    int value = v[i].first, pos = v[i].second;
    if (pos < n - 1 && ok[pos + 1]) merge(pos, pos + 1);
    if (pos > 0 && ok[pos - 1]) merge(pos, pos - 1);
    cur = max(tg[find(pos)], cur);
    if (i == n - 1 || v[i].first != v[i + 1].first) {
      for (int j = prev; j <= cur; ++j) ans[j] = v[i].first;
      prev = cur + 1;
    }
    ok[pos]++;
  }
  for (int i = 1; i < n + 1; i++) {
    cout << ans[i];
    if (i != n) cout << " ";
  }
  cout << endl;
  return 0;
}
