#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  vector<int> a;
  cin >> n;
  a.resize(n);
  for (auto &i : a) cin >> i;
  a.push_back(0);
  vector<int> hs{-1}, ps{-1}, max_strength(n + 1, -1);
  for (int i = 0; i <= n; ++i) {
    if (a[i] >= hs.back()) {
      hs.push_back(a[i]);
      ps.push_back(i);
    } else {
      int start, height;
      while (a[i] < hs.back()) {
        start = ps.back();
        height = hs.back();
        ps.pop_back();
        hs.pop_back();
        int length = i - start;
        max_strength[length] = max(max_strength[length], height);
      }
      hs.push_back(a[i]);
      ps.push_back(start);
    }
  }
  max_strength[n] = *min_element(a.begin(), a.end() - 1);
  for (int i = n - 1; i >= 0; --i) {
    max_strength[i] = max_strength[i + 1] > max_strength[i]
                          ? max_strength[i + 1]
                          : max_strength[i];
  }
  for (int i = 1; i <= n; ++i) {
    cout << max_strength[i] << " \n"[i == n];
  }
  return 0;
}
