#include <bits/stdc++.h>
typedef struct {
  int x, len;
} pair;
int n, l[200000], r[200000];
pair a[200000];
void quicksort(pair A[], int p, int q) {
  int i, k;
  pair x;
  if (p >= q) {
    return;
  }
  k = (p + q) / 2;
  x = A[q];
  A[q] = A[k];
  A[k] = x;
  k = p;
  for (i = p; i < q; i++) {
    if (A[i].x > A[q].x || (A[i].x == A[q].x && (i & 1))) {
      x = A[i];
      A[i] = A[k];
      A[k++] = x;
    }
  }
  x = A[q];
  A[q] = A[k];
  A[k] = x;
  quicksort(A, p, k - 1);
  quicksort(A, k + 1, q);
  return;
}
int main() {
  int i, j;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i].x);
  }
  l[0] = 0;
  for (i = 1; i < n; i++) {
    j = i - 1;
    while (a[j].x >= a[i].x) {
      if (l[j] == 0) {
        j = -1;
        break;
      }
      j = l[j] - 1;
    }
    l[i] = j + 1;
  }
  r[n - 1] = n - 1;
  a[n - 1].len = r[n - 1] - l[n - 1];
  for (i = n - 2; i >= 0; i--) {
    j = i + 1;
    while (a[j].x >= a[i].x) {
      if (r[j] == n - 1) {
        j = n;
        break;
      }
      j = r[j] + 1;
    }
    r[i] = j - 1;
    a[i].len = r[i] - l[i];
  }
  quicksort(a, 0, n - 1);
  j = 0;
  for (i = 0; i < n; i++) {
    while (a[j].len < i) {
      j++;
    }
    printf("%d%c", a[j].x, i == n - 1 ? '\n' : ' ');
  }
  return 0;
}
