#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, inf = 0x3f3f3f3f;
int n, top = 0, a[N], s[N];
int le[N], rg[N], ans[N];
priority_queue<pair<int, int> > q;
void solve() {
  int R = 0;
  while (!q.empty() && R < n) {
    pair<int, int> u = q.top();
    q.pop();
    int val = u.first, p = u.second;
    int len = rg[p] - le[p] + 1;
    while (R < len) ans[++R] = val;
  }
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    q.push(pair<int, int>(a[i], i));
    while (top && a[s[top]] > a[i]) rg[s[top]] = i - 1, top--;
    s[++top] = i;
  }
  while (top) rg[s[top]] = n, top--;
  for (int i = n; i >= 1; i--) {
    while (top && a[s[top]] > a[i]) le[s[top]] = i + 1, top--;
    s[++top] = i;
  }
  while (top) le[s[top]] = 1, top--;
  solve();
  return 0;
}
