#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
int partial[200005];
map<int, int> power;
stack<pair<int, int> > store;
int ans[200005];
vector<pair<int, int> > lefty(200005), righty(200005);
int main() {
  int n, a;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    lefty[i].first = a;
    lefty[i].second = 0;
    righty[i].second = 0;
    righty[i].first = a;
  }
  store.push({lefty[0].first, 0});
  int ind = 1, cnt = 0;
  while (!store.empty() && ind < n) {
    if (lefty[ind].first <= store.top().first) {
      while (!store.empty() && store.top().first >= lefty[ind].first) {
        lefty[ind].second += (lefty[store.top().second].second + 1);
        store.pop();
      }
      store.push({lefty[ind].first, ind});
    } else
      store.push({lefty[ind].first, ind});
    ind++;
  }
  while (!store.empty()) {
    store.pop();
  }
  store.push({lefty[n - 1].first, n - 1});
  ind = n - 2;
  while (!store.empty() && ind >= 0) {
    if (lefty[ind].first <= store.top().first) {
      while (!store.empty() && store.top().first >= lefty[ind].first) {
        righty[ind].second += (righty[store.top().second].second + 1);
        store.pop();
      }
      store.push({lefty[ind].first, ind});
    } else
      store.push({lefty[ind].first, ind});
    ind--;
  }
  int val;
  for (int i = 0; i < n; i++) {
    val = lefty[i].second + righty[i].second + 1;
    partial[val] = max(partial[val], lefty[i].first);
  }
  for (int i = n - 1; i >= 0; i--) {
    if (partial[i] < partial[i + 1]) partial[i] = partial[i + 1];
  }
  for (int i = 1; i < n + 1; i++) cout << partial[i] << " ";
  return 0;
}
