#include <bits/stdc++.h>
using namespace std;
struct node {
  int v, id;
  node(int _id) {
    id = _id;
    cin >> v;
  }
  bool operator<(const node& from) const { return v > from.v; }
};
vector<node> Q;
bool IN[200005];
int l[200005];
int r[200005];
int pt = 1, mx = 1;
void update(int x) {
  IN[x] = 1;
  if (IN[x - 1]) l[x] = l[x - 1];
  if (IN[x + 1]) r[x] = r[x + 1];
  r[l[x]] = r[x];
  l[r[x]] = l[x];
  mx = max(mx, r[x] - l[x] + 1);
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) Q.push_back(node(i));
  for (int i = 1; i <= n; i++) l[i] = r[i] = i;
  sort(Q.begin(), Q.end());
  int pt = 1;
  for (int i = 0; i < n; i++) {
    while (i < n and Q[i + 1].v == Q[i].v) update(Q[i++].id);
    update(Q[i].id);
    for (; pt <= mx; pt++) cout << Q[i].v << " ";
  }
  return 0;
}
