#include <bits/stdc++.h>
using namespace std;
const int n = 2e5 + 4;
int a[n], ans[n];
pair<int, int> b[n];
vector<int> v;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    while (v.size() && a[v.back()] >= a[i])
      b[i].first += b[v.back()].first + 1, v.pop_back();
    v.push_back(i);
  }
  v.clear();
  for (int i = n - 1; i >= 0; i--) {
    while (v.size() && a[v.back()] >= a[i])
      b[i].second += b[v.back()].second + 1, v.pop_back();
    v.push_back(i);
  }
  for (int i = 0; i < n; i++)
    ans[b[i].first + b[i].second + 1] =
        max(ans[b[i].first + b[i].second + 1], a[i]);
  for (int i = n - 1; i >= 1; i--) ans[i] = max(ans[i], ans[i + 1]);
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  return 0;
}
