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