#include <bits/stdc++.h>
using namespace std;
stack<pair<int, int>> st1, st2;
int b[300000], c[300000], a[300000], d[300000], e[300000], f[300000];
void st(int n) {
  int i = 0;
  st1.push(make_pair(a[0], i));
  b[0] = 0;
  i = 1;
  while (i < n) {
    if (st1.top().first < a[i])
      st1.push(make_pair(a[i], i)), b[i] = 0;
    else {
      while (st1.empty() == false && st1.top().first >= a[i]) st1.pop();
      if (st1.empty() == true)
        b[i] = i;
      else
        b[i] = i - st1.top().second - 1;
      st1.push(make_pair(a[i], i));
    }
    i++;
  }
  while (!st1.empty()) st1.pop();
}
int main() {
  int t, i, j, k, l, m, n;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  st(n);
  for (i = 0; i < n; i++) {
    c[i] = a[n - i - 1];
    e[i] = a[i];
    d[i] = b[i];
    b[i] = 0;
  }
  for (i = 0; i < n; i++) a[i] = c[i];
  st(n);
  m = 0;
  for (i = 0; i < n; i++) {
    f[b[n - 1 - i] + d[i] + 1] = max(f[b[n - 1 - i] + d[i] + 1], e[i]);
  }
  for (i = n - 1; i > 0; i--) f[i] = max(f[i], f[i + 1]);
  for (i = 1; i <= n; i++) printf("%d ", f[i]);
}
