#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 7;
int n, s[N], ans[N];
int main() {
  while (cin >> n) {
    memset(ans, 0, sizeof(ans));
    for (int i = 0; i < n; i++) scanf("%d", &s[i]);
    s[n] = 0;
    stack<int> st;
    int i = 0;
    while (i <= n) {
      if (st.empty() || s[st.top()] < s[i])
        st.push(i++);
      else {
        int wei = st.top();
        st.pop();
        int kk = st.empty() ? i : i - st.top() - 1;
        ans[kk] = max(s[wei], ans[kk]);
      }
    }
    for (int i = n - 1; i >= 1; i--) {
      if (ans[i] < ans[i + 1]) ans[i] = ans[i + 1];
    }
    for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
    printf("\n");
  }
  return 0;
}
