#include <bits/stdc++.h>
using namespace std;
template <typename T>
T pow(T a, T b, long long int m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans % m;
}
template <typename T>
void swap(T *a, T *b) {
  T temp = *a;
  *a = *b;
  *b = temp;
  return;
}
void solve() {
  long long int n;
  cin >> n;
  long long int arr[n];
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    cin >> arr[i];
  stack<long long int> st;
  long long int l[n], r[n];
  for (long long int i = 0; i < n; ++i) {
    while (st.empty() == false and arr[st.top()] >= arr[i]) st.pop();
    if (st.empty())
      l[i] = -1;
    else
      l[i] = st.top();
    st.push(i);
  }
  stack<long long int> st2;
  for (long long int i = n - 1; i >= 0; --i) {
    while (st2.empty() == false and arr[st2.top()] >= arr[i]) st2.pop();
    if (st2.empty())
      r[i] = n;
    else
      r[i] = st2.top();
    st2.push(i);
  }
  long long int ans[n + 5];
  memset(ans, 0, sizeof(ans));
  ;
  for (long long int i = 0; i < n; ++i) {
    long long int len = r[i] - l[i] - 1;
    ans[len] = max(ans[len], arr[i]);
  }
  for (long long int i = n; i >= 1; --i) {
    ans[i] = max(ans[i], ans[i + 1]);
  }
  for (__typeof(n + 1) i = (1) - ((1) > (n + 1));
       i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1)))
    cout << ans[i] << " ";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
  return 0;
}
