#include <bits/stdc++.h>
using namespace std;
const int N = 200500;
int a[N];
int larr[N], rarr[N], n, ans[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  stack<int> s;
  for (int i = 1; i <= n; i++) {
    while (!s.empty() && a[s.top()] >= a[i]) {
      s.pop();
    }
    if (s.empty()) {
      larr[i] = 0;
    } else {
      larr[i] = s.top();
    }
    s.push(i);
  }
  while (!s.empty()) s.pop();
  for (int i = n; i > 0; i--) {
    while (!s.empty() && a[s.top()] >= a[i]) {
      s.pop();
    }
    if (s.empty()) {
      rarr[i] = n + 1;
    } else {
      rarr[i] = s.top();
    }
    s.push(i);
  }
  memset(ans, 0, sizeof(ans));
  for (int i = 1; i <= n; i++) {
    int len = rarr[i] - larr[i] - 1;
    ans[len] = max(ans[len], 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;
}
