#include <bits/stdc++.h>
using namespace std;
inline void err(istringstream *iss) {}
template <typename T, typename... Args>
void err(istringstream *iss, const T &$val, const Args &...args) {
  string $name;
  *iss >> $name;
  if ($name.back() == ',') $name.pop_back();
  cout << $name << " = " << $val << "; ", err(iss, args...);
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
int n, m, K, T, Q, cn;
int a[200005];
int ans[200005], l[200005], r[200005];
int main() {
  cin.tie(NULL);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int stck[200005], si = 0;
  for (int i = 0; i < n; i++) {
    while (si and a[stck[si]] >= a[i]) --si;
    l[i] = si ? stck[si] : -1;
    stck[++si] = i;
  }
  si = 0;
  for (int i = n - 1; i >= 0; i--) {
    while (si and a[stck[si]] >= a[i]) --si;
    r[i] = si ? stck[si] : n;
    stck[++si] = i;
  }
  for (int i = 0; i < n; i++) {
    ans[r[i] - l[i] - 1] = max(ans[r[i] - l[i] - 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++) {
    printf("%d%c", ans[i], " \n"[i == n]);
  }
  return 0;
}
