#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, a[N], st[N], top, l[N], r[N], mx[N];
inline int read() {
  int ret = 0, ff = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    ret = ret * 10 + (ch ^ 48);
    ch = getchar();
  }
  return ret * ff;
}
void write(int x) {
  if (x < 0) {
    x = -x, putchar('-');
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + 48);
}
void writeln(int x) { write(x), puts(""); }
void writesp(int x) { write(x), putchar(' '); }
signed main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= n; i++) {
    while (top && a[i] <= a[st[top]]) top--;
    l[i] = st[top] + 1;
    st[++top] = i;
  }
  top = 0;
  st[0] = n + 1;
  for (int i = n; i >= 1; i--) {
    while (top && a[i] <= a[st[top]]) top--;
    r[i] = st[top] - 1;
    st[++top] = i;
  }
  for (int i = 1; i <= n; i++) {
    int len = r[i] - l[i] + 1;
    mx[len] = max(mx[len], a[i]);
  }
  for (int i = n - 1; i >= 1; i--) mx[i] = max(mx[i], mx[i + 1]);
  for (int i = 1; i <= n; i++) writesp(mx[i]);
  return 0;
}
