#include <bits/stdc++.h>
using namespace std;
int A[200010];
int l[200010];
int r[200010];
int size[200010];
int answer[200010];
int n;
void left() {
  stack<int> st;
  for (int i = 0; i < n; i++) {
    while (st.size() && A[st.top()] >= A[i]) st.pop();
    if (st.size() == 0)
      l[i] = -1;
    else
      l[i] = st.top();
    st.push(i);
  }
}
void right() {
  stack<int> st;
  for (int i = n - 1; i >= 0; i--) {
    while (st.size() && A[st.top()] >= A[i]) st.pop();
    if (st.size() == 0)
      r[i] = n;
    else
      r[i] = st.top();
    st.push(i);
  }
}
bool mysort(pair<int, int>& A, pair<int, int>& B) {}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> A[i];
  left();
  right();
  for (int i = 0; i < n; i++) {
    size[i] = r[i] - l[i] - 1;
  }
  map<int, int> m1;
  map<int, int> m2;
  for (int i = 0; i < n; i++) {
    if (m1.find(A[i]) != m1.end()) {
      if (m1.find(A[i])->second < size[i]) {
        m1.erase(m1.find(A[i]));
        m1.insert(make_pair(A[i], size[i]));
      }
    } else {
      m1.insert(make_pair(A[i], size[i]));
    }
  }
  for (map<int, int>::reverse_iterator i = m1.rbegin(); i != m1.rend(); i++) {
    for (int j = i->second - 1; answer[j] == 0 && j >= 0; j--)
      answer[j] = i->first;
  }
  for (int i = 0; i < n; i++) cout << answer[i] << " ";
}
