#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int inf = 0x3f3f3f3f;
int n;
int a[maxn], l[maxn], r[maxn];
int s[maxn], top;
int ans[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    while (top && a[s[top]] >= a[i]) top--;
    if (top)
      l[i] = s[top] + 1;
    else
      l[i] = 1;
    s[++top] = i;
  }
  top = 0;
  for (int i = n; i >= 1; i--) {
    while (top && a[s[top]] >= a[i]) top--;
    if (top)
      r[i] = s[top] - 1;
    else
      r[i] = n;
    s[++top] = i;
  }
  for (int i = 1; i <= n; i++) {
    int len = r[i] - l[i] + 1;
    ans[len] = max(ans[len], a[i]);
  }
  for (int i = n - 1; i >= 1; i--) ans[i] = max(ans[i + 1], ans[i]);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
