#include <bits/stdc++.h>
int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}
int main() {
  int t = 1, n, i;
  int a[200005];
  while (t--) {
    int dpl[200005], dpr[200005], st[200005], len[200005];
    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    for (i = 0; i < n; i++) {
      dpl[i] = -1;
      dpr[i] = n;
    }
    int k = 0;
    for (i = 0; i < n; i++) {
      while (k > 0 && a[st[k - 1]] >= a[i]) k--;
      if (k > 0) dpl[i] = st[k - 1];
      st[k++] = i;
    }
    k = 0;
    for (i = n - 1; i >= 0; i--) {
      while (k > 0 && a[st[k - 1]] >= a[i]) k--;
      if (k > 0) dpr[i] = st[k - 1];
      st[k++] = i;
    }
    for (i = 0; i <= n; i++) len[i] = 0;
    int x;
    for (i = 0; i < n; i++) {
      x = dpr[i] - dpl[i] - 1;
      len[x] = max(len[x], a[i]);
    }
    for (i = n - 1; i >= 0; i--) len[i] = max(len[i], len[i + 1]);
    for (i = 1; i < n; i++) printf("%d ", len[i]);
    printf("%d\n", len[n]);
  }
  return 0;
}
