#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int visit[1000001];
int par[1000001];
int size[1000001];
int ans[1000001];
int find(int x) {
  while (x != par[x]) {
    x = par[x];
  }
  return x;
}
void u(int x, int y) {
  x = find(x);
  y = find(y);
  par[x] = y;
  size[y] = size[x] + size[y];
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(make_pair(x, i + 1));
    par[i + 1] = i + 1;
    size[i + 1] = 1;
    visit[i + 1] = 0;
  }
  sort(v.begin(), v.end());
  vector<pair<int, int> >::reverse_iterator it;
  int cur = 1;
  for (it = v.rbegin(); it != v.rend(); it++) {
    int val = it->first;
    int pos = it->second;
    visit[pos] = 1;
    if (pos > 1 && visit[pos - 1]) u(pos - 1, pos);
    if (pos < n && visit[pos + 1]) u(pos + 1, pos);
    while (cur <= size[find(pos)]) ans[cur++] = val;
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
}
