#include <bits/stdc++.h>
using namespace std;
long long int par[1234567];
long long int sz[1234567];
bool vis[1234567];
long long int Find(long long int u) {
  if (par[u] == -1) return u;
  return par[u] = Find(par[u]);
}
void Merge(long long int u, long long int v) {
  long long int pu = Find(u), pv = Find(v);
  par[pu] = pv, sz[pv] += sz[pu];
  return;
}
int main() {
  ios::sync_with_stdio(0);
  long long int n;
  cin >> n;
  pair<long long int, long long int> a[n + 1];
  long long int b[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i, b[i] = a[i].first;
  }
  sort(a, a + n, greater<pair<long long int, long long int> >());
  sort(b, b + n, greater<long long int>());
  memset(par, -1, sizeof par);
  memset(vis, 0, sizeof vis);
  for (int i = 0; i <= 1e6; i++) sz[i] = 1;
  long long int aux = 1;
  vector<long long int> sol;
  for (int i = 0; i < n; i++) {
    vis[a[i].second] = 1;
    if (a[i].second != n - 1 && vis[a[i].second + 1]) {
      Merge(a[i].second, a[i].second + 1);
    }
    if (a[i].second != 0 && vis[a[i].second - 1]) {
      Merge(a[i].second, a[i].second - 1);
    }
    int aaux = Find(a[i].second);
    while (sz[aaux] >= aux) sol.push_back(a[i].first), aux++;
  }
  for (int i = 0; i < sol.size(); i++) cout << sol[i] << " ";
}
