#include <bits/stdc++.h>
using namespace std;
int N, a[200000], l[200000], r[200000], ans[200000];
int main() {
  scanf("%d", &N);
  for (int n = 0; n < int(N); n++) scanf("%d", a + n);
  {
    priority_queue<pair<int, int> > pq;
    for (int n = 0; n < int(N); n++) {
      while (!pq.empty() && pq.top().first > a[n]) {
        pair<int, int> pt = pq.top();
        pq.pop();
        r[pt.second] = n;
      }
      pq.emplace(a[n], n);
      r[n] = N;
    }
  }
  {
    priority_queue<pair<int, int> > pq;
    for (int n = N - 1; n >= 0; n--) {
      while (!pq.empty() && pq.top().first > a[n]) {
        pair<int, int> pt = pq.top();
        pq.pop();
        l[pt.second] = n;
      }
      pq.emplace(a[n], n);
      l[n] = -1;
    }
  }
  for (int n = 0; n < int(N); n++)
    ans[r[n] - l[n] - 2] = max(ans[r[n] - l[n] - 2], a[n]);
  for (int n = N - 2; n >= 0; n--) ans[n] = max(ans[n], ans[n + 1]);
  for (int n = 0; n < int(N); n++)
    printf("%d%c", ans[n], n == N - 1 ? '\n' : ' ');
}
