#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
const int maxv = 1000000010;
int a[maxn];
int l[maxn], r[maxn];
int rj[maxn];
stack<int> s;
int main() {
  int n;
  cin >> n;
  a[0] = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  a[n + 1] = 0;
  s.push(0);
  for (int i = 1; i < n + 1; i++) {
    while (a[s.top()] >= a[i]) s.pop();
    l[i] = s.top();
    s.push(i);
  }
  while (s.size()) s.pop();
  s.push(n + 1);
  for (int i = n; i > 0; i--) {
    while (a[s.top()] >= a[i]) s.pop();
    r[i] = s.top();
    s.push(i);
  }
  for (int i = 1; i <= n; i++)
    rj[r[i] - l[i] - 1] = max(rj[r[i] - l[i] - 1], a[i]);
  int val = 0;
  for (int i = n; i > 0; i--) {
    val = max(val, rj[i]);
    rj[i] = val;
  }
  for (int i = 1; i <= n; i++) printf("%d ", rj[i]);
  return 0;
}
