#include <bits/stdc++.h>
const int MOD = 1000000007;
const int MAX_N = 2e5 + 10;
const int base = 37;
using namespace std;
int sz[MAX_N], pr[MAX_N];
int find(int v) {
  if (v == pr[v]) return v;
  return pr[v] = find(pr[v]);
}
void Union(int u, int v) {
  int f = find(u), s = find(v);
  if (sz[f] > sz[s]) swap(f, s);
  pr[f] = s;
  sz[s] += sz[f];
}
bool vis[MAX_N];
int cur;
int res[MAX_N];
int main() {
  for (int i = 0; i < MAX_N; i++) {
    pr[i] = i;
    sz[i] = 1;
  }
  int n;
  scanf("%d", &n);
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i].first);
    a[i].second = i + 1;
  }
  sort(a.begin(), a.end(), greater<pair<int, int>>());
  for (int i = 0; i < n; i++) {
    vis[a[i].second] = true;
    if (vis[a[i].second - 1]) Union(a[i].second, a[i].second - 1);
    if (vis[a[i].second + 1]) Union(a[i].second, a[i].second + 1);
    int theS = sz[find(a[i].second)];
    while (cur < theS) {
      res[cur] = a[i].first;
      cur++;
    }
  }
  for (int i = 0; i < n; i++) printf("%d ", res[i]);
  printf("\n");
}
