#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  vector<int> prev(n, -1), next(n, n);
  stack<int> st, st2;
  for (int i = 0; i < n; i++) {
    while (!st.empty() && arr[st.top()] >= arr[i]) {
      st.pop();
    }
    if (!st.empty()) prev[i] = st.top();
    st.push(i);
  }
  for (int i = n - 1; i >= 0; i--) {
    while (!st2.empty() && arr[st2.top()] >= arr[i]) st2.pop();
    if (!st2.empty()) next[i] = st2.top();
    st2.push(i);
  }
  vector<int> ans(n, 0);
  for (int i = 0; i < n; i++)
    ans[next[i] - prev[i] - 2] = max(ans[next[i] - prev[i] - 2], arr[i]);
  for (int i = n - 2; i >= 0; i--) ans[i] = max(ans[i], ans[i + 1]);
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
}
