#include <bits/stdc++.h>
using namespace std;
template <class T>
int getbit(int i, T X) {
  return (X & (1 << (i - 1)));
}
template <class T>
T onbit(int i, T X) {
  return (X | (1 << (i - 1)));
}
template <class T>
T offbit(int i, T X) {
  return (X | (1 << (i - 1)) - (1 << (i - 1)));
}
template <class T>
T sqr(T x) {
  return (x * x);
}
template <class T>
T cube(T x) {
  return (x * x * x);
}
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
int csx[4] = {0, 0, -1, 1};
int csy[4] = {-1, 1, 0, 0};
const int MOD = 1000000007;
const int maxn = 200005;
int n, a[maxn + 5], result[maxn + 5], l[maxn + 5], r[maxn + 5], p[maxn + 5];
pair<int, int> q[maxn + 5];
void enter() {
  cin >> n;
  for (typeof(n) i = 1; i <= n; i++) cin >> a[i];
}
void init() {
  stack<int> st;
  st.push(0);
  a[0] = -1;
  a[n + 1] = -1;
  for (typeof(n + 1) i = 1; i <= n + 1; i++) {
    while (a[i] < a[st.top()]) {
      r[st.top()] = i;
      st.pop();
    }
    if (a[i] == a[st.top()])
      l[i] = l[st.top()];
    else
      l[i] = st.top();
    st.push(i);
  }
}
void solve() {
  for (typeof(n) i = 1; i <= n; i++) p[i] = 0;
  for (typeof(n) i = 1; i <= n; i++) {
    int len = r[i] - l[i] - 1;
    p[len] = max(p[len], a[i]);
  }
  int m = 0;
  for (typeof(n) i = 1; i <= n; i++) {
    if (p[i] == 0) continue;
    m++;
    q[m] = make_pair(p[i], i);
  }
  sort(q + 1, q + m + 1);
  reverse(q + 1, q + m + 1);
  int finish = -1;
  for (typeof(m) i = 1; i <= m; i++) {
    if (q[i].second < finish) continue;
    for (typeof(q[i].second) j = finish + 1; j <= q[i].second; j++)
      result[j] = q[i].first;
    finish = q[i].second;
  }
  for (typeof(n) i = 1; i <= n; i++) cout << result[i] << " ";
}
int main() {
  enter();
  init();
  solve();
  return 0;
}
