#include <bits/stdc++.h>
using namespace std;
int a[1000010], l[1000010], r[1000010], res[1000010];
stack<int> s;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) {
    while (!s.empty() && a[s.top()] >= a[i]) s.pop();
    if (!s.empty())
      l[i] = s.top();
    else
      l[i] = -1;
    s.push(i);
  }
  while (!s.empty()) s.pop();
  for (int i = n - 1; i >= 0; i--) {
    while (!s.empty() && a[s.top()] >= a[i]) s.pop();
    if (!s.empty())
      r[i] = s.top();
    else
      r[i] = n;
    s.push(i);
  }
  for (int i = 0; i < n; i++)
    res[r[i] - l[i] - 1] = max(res[r[i] - l[i] - 1], a[i]);
  for (int i = n - 1; i > 0; i--) res[i] = max(res[i], res[i + 1]);
  for (int i = 1; i <= n; i++) printf("%d ", res[i]);
}
