#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
int par[maxn];
int get_par(int v) {
  if (par[v] < 0) return v;
  return par[v] = get_par(par[v]);
}
void merge(int v, int u) {
  v = get_par(v), u = get_par(u);
  par[u] += par[v];
  par[v] = u;
}
pair<int, int> a[maxn];
bool mark[maxn];
int ans[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + n + 1, greater<pair<int, int> >());
  memset(par, -1, sizeof par);
  int ptr = 1;
  for (int i = 1; i <= n; i++) {
    int idx = a[i].second;
    if (mark[idx + 1]) merge(idx, idx + 1);
    if (mark[idx - 1]) merge(idx, idx - 1);
    mark[idx] = 1;
    idx = get_par(idx);
    while (ptr <= -par[idx]) {
      ans[ptr++] = a[i].first;
    }
  }
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  cout << endl;
}
