#include <bits/stdc++.h>
using namespace std;
int n;
int a[211111];
int k[211111];
int ptr[211111];
int gss[211111];
int aus[211111];
int parrot(int node) {
  if (ptr[node] == node) return node;
  return ptr[node] = parrot(ptr[node]);
}
void unioka(int n1, int n2) {
  int par1 = parrot(n1);
  int par2 = parrot(n2);
  gss[par2] += gss[par1];
  ptr[par1] = par2;
}
int main(int argc, char* argv[]) {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[k[i] = ptr[i] = i];
  sort(k, k + n, [&](int l, int r) { return a[l] > a[r]; });
  int minaus = 0;
  for (int i = 0; i < n; ++i) {
    int ki = k[i];
    gss[ki] = 1;
    if (ki > 0 && gss[ki - 1]) unioka(ki, ki - 1);
    if (ki < n - 1 && gss[ki + 1]) unioka(ki, ki + 1);
    int neus = gss[parrot(ki)];
    if (neus > minaus) {
      for (int sis = minaus + 1; sis <= neus; ++sis) {
        aus[sis] = a[ki];
      }
      minaus = neus;
    }
  }
  for (int i = 1; i <= n; ++i) cout << aus[i] << ' ';
  cout << endl;
  return 0;
}
