#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long s = 0, f = 1;
  char ch;
  while (!isdigit(ch = getchar())) (ch == '-') && (f = -f);
  for (s = ch ^ 48; isdigit(ch = getchar());
       s = (s << 1) + (s << 3) + (ch ^ 48))
    ;
  return s * f;
}
const int N = 1e6 + 5;
int n, top;
int a[N], r[N], l[N], sta[N], ans[N];
int main() {
  n = read();
  for (register int i = 1; i <= n; i++) a[i] = read();
  for (register int i = 1; i <= n; i++) {
    while (top && a[sta[top]] > a[i]) r[sta[top--]] = i - 1;
    sta[++top] = i;
  }
  while (top) r[sta[top--]] = n;
  for (register int i = n; i >= 1; i--) {
    while (top && a[sta[top]] > a[i]) l[sta[top--]] = i + 1;
    sta[++top] = i;
  }
  while (top) l[sta[top--]] = 1;
  for (register int i = 1; i <= n; i++)
    ans[r[i] - l[i] + 1] = max(ans[r[i] - l[i] + 1], a[i]);
  for (register int i = n; i >= 1; i--) ans[i] = max(ans[i], ans[i + 1]);
  for (register int i = 1; i <= n; i++) printf("%d ", ans[i]);
  fclose(stdin);
  fclose(stdout);
  return 0;
}
