#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int n;
void solve() {
  cin >> n;
  vector<long long int> height(n);
  for (int i = 0; i < n; ++i) {
    cin >> height[i];
  }
  vector<long long int> leftRange(n, -1);
  vector<long long int> rightRange(n, n);
  vector<long long int> maxStrenth(n, 0);
  stack<int> prev;
  for (int i = 0; i < n; ++i) {
    while (!prev.empty() && height[prev.top()] >= height[i]) {
      prev.pop();
    }
    if (!prev.empty()) {
      leftRange[i] = prev.top();
    }
    prev.push(i);
  }
  while (!prev.empty()) {
    prev.pop();
  }
  for (int i = n - 1; i >= 0; --i) {
    while (!prev.empty() && height[prev.top()] >= height[i]) {
      prev.pop();
    }
    if (!prev.empty()) {
      rightRange[i] = prev.top();
    }
    prev.push(i);
  }
  for (int i = 0; i < n; ++i) {
    int range = rightRange[i] - leftRange[i] - 2;
    maxStrenth[range] = max(height[i], maxStrenth[range]);
  }
  for (int i = n - 2; i >= 0; --i) {
    maxStrenth[i] = max(maxStrenth[i], maxStrenth[i + 1]);
  }
  for (int i = 0; i < n; ++i) {
    cout << maxStrenth[i] << " ";
  }
  cout << '\n';
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int tests;
  solve();
  return 0;
}
