#include <bits/stdc++.h>
using namespace std;
int L[200010], R[200010];
int a[200010];
int b[200010];
int c[200010];
int dt[200010];
int Rmax[200010];
int cmp(int i, int j) { return dt[i] < dt[j]; }
int stk[200010];
int top = 1;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  L[1] = n + 1;
  top = 1;
  stk[top] = 1;
  for (int i = 2; i <= n; i++) {
    if (a[i] > a[i - 1])
      L[i] = 1;
    else {
      while (top && a[stk[top]] >= a[i]) top--;
      if (top)
        L[i] = i - stk[top];
      else
        L[i] = n + 1;
    }
    stk[++top] = i;
  }
  R[n] = n + 1;
  top = 1;
  stk[top] = n;
  for (int i = n - 1; i >= 1; i--) {
    if (a[i] > a[i + 1])
      R[i] = 1;
    else {
      while (top && a[stk[top]] >= a[i]) top--;
      if (top)
        R[i] = stk[top] - i;
      else
        R[i] = n + 1;
    }
    stk[++top] = i;
  }
  for (int i = 1; i <= n; i++)
    if (R[i] == n + 1 && L[i] == n + 1)
      dt[i] = n + 1;
    else if (R[i] != n + 1 && L[i] != n + 1)
      dt[i] = abs(R[i] + L[i] - 1);
    else if (R[i] == n + 1)
      dt[i] = n - i + L[i];
    else
      dt[i] = i - 1 + R[i];
  for (int i = 1; i <= n; i++) b[i] = i;
  sort(b + 1, b + n + 1, cmp);
  sort(dt + 1, dt + n + 1);
  for (int i = 1; i <= n; i++) {
    c[i] = a[b[i]];
  }
  Rmax[n] = c[n];
  for (int i = n - 1; i >= 1; i--) Rmax[i] = max(Rmax[i + 1], c[i]);
  for (int i = 1; i <= n; i++) {
    int id = lower_bound(dt + 1, dt + n + 1, i) - (dt);
    printf("%d ", Rmax[id]);
  }
  return 0;
}
