#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int N = 1e6 + 5;
int arr[N];
int n;
int lt[N];
int rt[N];
int ans[N];
stack<int> st1, st2;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", arr + i);
    rt[i] = n + 1;
  }
  for (int i = n; i >= 1; i--) {
    while (!st1.empty() && arr[st1.top()] >= arr[i]) {
      st1.pop();
    }
    if (!st1.empty()) {
      rt[i] = st1.top();
    }
    st1.push(i);
  }
  for (int i = 1; i <= n; i++) {
    while (!st2.empty() && arr[st2.top()] >= arr[i]) {
      st2.pop();
    }
    if (!st2.empty()) {
      lt[i] = st2.top();
    }
    st2.push(i);
  }
  for (int i = 1; i <= n; i++) {
    int temp = rt[i] - lt[i] - 1;
    ans[temp] = max(ans[temp], arr[i]);
  }
  for (int i = n; i >= 1; i--) {
    ans[i] = max(ans[i], ans[i + 1]);
  }
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
