#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 3e5 + 10;
constexpr int MOD = 1e9 + 7;
constexpr int INF = 2e9 + 3;
constexpr int LOG = 31;
int n, a[MAXN], part[MAXN], l[MAXN], r[MAXN];
vector<pair<int, int>> vc;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (vc.empty()) {
      vc.push_back(make_pair(a[i], i));
      l[i] = 0;
    } else if (vc.back().first <= a[i]) {
      int tmp = vc.back().second;
      l[i] = tmp;
      vc.push_back(make_pair(a[i], i));
    } else {
      while (!vc.empty() && vc.back().first > a[i]) {
        r[vc.back().second] = i;
        vc.pop_back();
      }
      if (vc.empty()) {
        vc.push_back(make_pair(a[i], i));
        l[i] = 0;
      } else {
        l[i] = vc.back().second;
        vc.push_back(make_pair(a[i], i));
      }
    }
  }
  while (!vc.empty()) {
    r[vc.back().second] = n + 1;
    vc.pop_back();
  }
  for (int i = 1; i <= n; i++) {
    int tmp = r[i] - l[i] - 1;
    part[tmp] = max(a[i], part[tmp]);
  }
  for (int i = n; i >= 1; i--) {
    part[i] = max(part[i], part[i + 1]);
  }
  for (int i = 1; i <= n; i++) {
    cout << part[i] << " ";
  }
  return 0;
}
