#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:255000000")
bool firstout = 1;
template <class T>
T &minn(T &a, T b) {
  if (b < a) a = b;
  return a;
}
template <class T>
T &maxx(T &a, T b) {
  if (a < b) a = b;
  return a;
}
int &madd(int &a, int b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
  return a;
}
int &msub(int &a, int b) {
  a -= b;
  if (a < 0) a += 1000000007;
  return a;
}
int &mmult(int &a, int b) { return a = (long long)a * b % 1000000007; }
int mdiv(long long a, long long b, long long m) {
  a = (a % m + m) % m;
  b = (b % m + m) % m;
  if (a % b == 0) return a / b;
  return (a + m * mdiv(-a, m, b)) / b;
}
int n, m, q;
pair<int, int> A[201234];
int main() {
  int i, j, k;
  char c;
  int a, d;
  int ts;
  for (ts = 1; scanf("%"
                     "d",
                     &(n)) > 0;
       ++ts) {
    for (i = (0); i < (n); ++i)
      scanf(
          "%"
          "d",
          &(A[i].first)),
          A[i].second = i;
    sort(A, A + n);
    reverse(A, A + n);
    set<pair<int, int> > s;
    set<pair<int, int> >::iterator si;
    k = 0;
    for (i = (0); i < (n); ++i) {
      pair<int, int> p = make_pair(A[i].second, 1), pp;
      si = s.lower_bound(p);
      if (si != s.begin()) {
        pp = *--si;
        if (pp.first + pp.second == p.first) {
          s.erase(pp);
          p = make_pair(pp.first, pp.second + p.second);
        }
      }
      si = s.lower_bound(p);
      if (si != s.end()) {
        pp = *si;
        if (p.first + p.second == pp.first) {
          s.erase(pp);
          p = make_pair(p.first, p.second + pp.second);
        }
      }
      for (; k < p.second; ++k)
        printf((firstout) ? "%"
                            "d"
                          : " %"
                            "d",
               (A[i].first)),
            firstout = 0;
      s.insert(p);
    }
    printf("\n"), firstout = 1;
  }
  return 0;
}
