#include <bits/stdc++.h>
using namespace std;
const int INF = 987654321;
int main() {
  ios_base::sync_with_stdio(false);
  cout.precision(10);
  cout << fixed;
  int n;
  cin >> n;
  vector<int> a(n + 1, 0);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  vector<int> l(n + 1, 0);
  vector<int> r(n + 1, 0);
  stack<int> st;
  for (int i = 1; i <= n; ++i) {
    while (!st.empty() && a[st.top()] >= a[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() && a[st.top()] >= a[i]) st.pop();
    if (st.empty())
      r[i] = n + 1;
    else
      r[i] = st.top();
    st.push(i);
  }
  vector<int> res(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int len = r[i] - l[i] - 1;
    res[len] = max(res[len], a[i]);
  }
  for (int i = n - 1; i >= 1; --i) res[i] = max(res[i], res[i + 1]);
  for (int i = 1; i <= n; ++i) cout << res[i] << " ";
  cout << "\n";
  return 0;
}
