#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> h;
vector<int> db;
int main() {
  cin >> n;
  h.resize(n);
  db.resize(n);
  stack<pair<int, int>> st;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    while (!st.empty() && st.top().first >= h[i]) {
      st.pop();
    }
    db[i] = i - (st.empty() ? -1 : st.top().second);
    st.push(make_pair(h[i], i));
  }
  st = stack<pair<int, int>>();
  int mx = 0;
  priority_queue<pair<int, int>> pq;
  for (int i = n - 1; i >= 0; i--) {
    while (!st.empty() && st.top().first >= h[i]) {
      st.pop();
    }
    db[i] += (st.empty() ? n : st.top().second) - i - 1;
    mx = max(mx, db[i] * h[i]);
    st.push(make_pair(h[i], i));
    pq.push(make_pair(h[i], db[i]));
  }
  for (int x = 1; x <= n; x++) {
    while (pq.top().second < x) {
      pq.pop();
    }
    cout << pq.top().first << " ";
  }
  return 0;
}
