#include <bits/stdc++.h>
using namespace std;
const int mxn = 2e5 + 10;
int lt[mxn], rt[mxn], arr[mxn];
multiset<array<int, 2>> in1, in2;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  vector<int> q;
  for (int i = 1; i <= n; i++) {
    while ((int)q.size() && arr[q.back()] >= arr[i]) q.pop_back();
    lt[i] = i - (q.size() ? q.back() : 0), q.push_back(i);
  }
  while (q.size()) q.pop_back();
  for (int i = n; i; i--) {
    while ((int)q.size() && arr[q.back()] >= arr[i]) q.pop_back();
    rt[i] = q.size() ? q.back() - i : n - i + 1, q.push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    in1.insert({lt[i] + rt[i] - 1, arr[i]});
    in2.insert({arr[i], lt[i] + rt[i] - 1});
  }
  for (int i = 1; i <= n; i++) {
    while ((int)in1.size() && (*in1.begin())[0] < i) {
      array<int, 2> arr = *in1.begin();
      in2.erase(in2.lower_bound({arr[1], arr[0]}));
      in1.erase(in1.begin());
    }
    assert(in1.size() && in2.size());
    printf("%d ", (*in2.rbegin())[0]);
  }
}
