#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long a[n], nxt[n], pre[n], ans[n + 1];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    nxt[i] = n;
    pre[i] = -1;
  }
  memset(ans, 0, sizeof ans);
  stack<long long> st;
  for (long long i = 0; i < n; i++) {
    while (!st.empty() and a[st.top()] >= a[i]) st.pop();
    if (!st.empty()) pre[i] = st.top();
    st.push(i);
  }
  while (!st.empty()) st.pop();
  for (long long i = n - 1; i >= 0; i--) {
    while (!st.empty() and a[st.top()] >= a[i]) st.pop();
    if (!st.empty()) nxt[i] = st.top();
    st.push(i);
  }
  for (long long i = 0; i < n; i++)
    ans[nxt[i] - pre[i] - 1] = max(ans[nxt[i] - pre[i] - 1], a[i]);
  for (long long i = n - 1; i >= 1; i--) ans[i] = max(ans[i], ans[i + 1]);
  for (long long i = 1; i <= n; i++) cout << ans[i] << " ";
  return 0;
}
