#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, a[N], ans[N], lef[N], rig[N];
stack<int> st;
void input() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
}
void solve() {
  memset(ans, 0, sizeof(ans));
  for (int i = 1; i <= n; i++) lef[i] = 0;
  for (int i = 1; i <= n; i++) rig[i] = n + 1;
  for (int i = 1; i <= n; i++) {
    while (!st.empty() && a[st.top()] >= a[i]) st.pop();
    if (!st.empty()) lef[i] = st.top();
    st.push(i);
  }
  while (!st.empty()) st.pop();
  for (int i = n; i >= 1; i--) {
    while (!st.empty() && a[st.top()] >= a[i]) st.pop();
    if (!st.empty()) rig[i] = st.top();
    st.push(i);
  }
  for (int i = 1; i <= n; i++)
    ans[rig[i] - lef[i] - 1] = max(ans[rig[i] - lef[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 ", ans[i]);
}
int main() {
  input();
  solve();
  return 0;
}
