#include <bits/stdc++.h>
using namespace std;
int n, m[200010];
set<int> s;
struct P {
  int i, x;
  bool operator<(const P& p) const { return x < p.x; }
} p[200010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    p[i].i = i;
    p[i].x = x;
  }
  sort(&p[1], &p[n + 1]);
  s.insert(0);
  s.insert(n + 1);
  for (int i = 1; i <= n; i++) {
    set<int>::iterator L = s.upper_bound(p[i].i), R = L;
    L--;
    m[i] = *R - *L - 1;
    s.insert(p[i].i);
  }
  int cnt = 0;
  for (int i = n; i > 0 && cnt < n; i--) {
    int P = 0;
    for (int j = cnt; j < m[i]; j++) printf("%d ", p[i].x), P++;
    cnt += P;
  }
  return 0;
}
