#include <bits/stdc++.h>
using namespace std;
int n, ans;
int v[200009], d[200009];
pair<int, int> info[200009];
vector<int> st;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    while (!st.empty() && v[i] < v[st.back()])
      info[st.back()].second = i, st.pop_back();
    if (st.empty())
      info[i].first = 0;
    else {
      if (v[st.back()] == v[i])
        info[i].first = info[st.back()].first;
      else
        info[i].first = st.back();
    }
    info[i].second = n + 1, st.push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    int dist = info[i].second - (info[i].first + 1);
    d[dist] = max(d[dist], v[i]);
  }
  for (int i = n; i >= 1; i--) d[i] = max(d[i], d[i + 1]);
  for (int i = 1; i <= n; i++) cout << d[i] << " ";
}
