#include <bits/stdc++.h>
using namespace std;
int n;
int a[200010], l[200010], r[200010];
int ans[200010];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    l[i] = r[i] = i;
  }
  for (int i = 2; i <= n; i++) {
    while (l[i] > 1 && a[i] <= a[l[i] - 1]) {
      l[i] = l[l[i] - 1];
    }
  }
  for (int i = n - 1; i >= 1; i--) {
    while (r[i] < n && a[i] <= a[r[i] + 1]) {
      r[i] = r[r[i] + 1];
    }
  }
  for (int i = 1; i <= n; i++) {
    int len = r[i] - l[i] + 1;
    ans[len] = max(ans[len], a[i]);
  }
  for (int i = n; i >= 1; i--) {
    if (ans[i] == 0 || ans[i] < ans[i + 1]) ans[i] = ans[i + 1];
  }
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
