#include <bits/stdc++.h>
using namespace std;
int arr[204800], len[204800], ans[204800];
int l[204800], r[204800];
pair<int, int> w[204800];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  stack<int> st;
  for (int i = 1; i <= n; i++) {
    while (!st.empty() && arr[st.top()] >= arr[i]) st.pop();
    if (st.empty())
      l[i] = 0;
    else
      l[i] = st.top();
    st.push(i);
  }
  while (!st.empty()) st.pop();
  for (int i = n; i >= 1; i--) {
    while (!st.empty() && arr[st.top()] >= arr[i]) st.pop();
    if (st.empty())
      r[i] = n + 1;
    else
      r[i] = st.top();
    st.push(i);
  }
  for (int i = 1; i <= n; i++) {
    w[i].first = -arr[i];
    w[i].second = r[i] - l[i] - 1;
  }
  sort(w + 1, w + n + 1);
  for (int i = 1; i <= n; i++) {
    arr[i] = -w[i].first;
    len[i] = w[i].second;
  }
  ans[0] = 0x3FFFFFFF;
  for (int i = 1; i <= n; i++) {
    int np = len[i];
    while (ans[np] < arr[i]) {
      ans[np] = arr[i];
      np--;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
