#include <bits/stdc++.h>
using namespace std;
const double eps = 1.0e-5;
const double PI = acos(-1.0);
template <class T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
T _abs(T a) {
  return a > 0 ? a : -a;
}
const int maxn = 200010;
pair<int, int> a[maxn];
int l[maxn], r[maxn];
bool cmp(pair<int, int> x, pair<int, int> y) {
  if (x.first != y.first) return x.first > y.first;
  return x.second < y.second;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i].first);
  l[1] = 1;
  for (int i = 2; i <= n; i++) {
    int t = i - 1;
    while (t > 0 && a[i] <= a[t]) t = l[t] - 1;
    l[i] = t + 1;
  }
  r[n] = n;
  for (int i = n - 1; i > 0; i--) {
    int t = i + 1;
    while (t <= n && a[i] <= a[t]) t = r[t] + 1;
    r[i] = t - 1;
  }
  for (int i = 1; i <= n; i++) a[i].second = r[i] - l[i] + 1;
  sort(a + 1, a + n + 1, cmp);
  int j = 1;
  for (int i = 1; i <= n; i++) {
    while (a[j].second < i) j++;
    printf("%d%c", a[j].first, i == n ? '\n' : ' ');
  }
  return 0;
}
