#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n), l(n), r(n), result(n + 1, 0);
  for (long long i = (0); i < (n); i++) scanf("%d", &a[i]);
  stack<int> st;
  for (long long i = (0); i < (n); i++) {
    while (!st.empty() && a[i] <= a[st.top()]) st.pop();
    if (st.empty())
      l[i] = -1;
    else
      l[i] = st.top();
    st.push(i);
  }
  while (!st.empty()) st.pop();
  for (long long i = (n - 1); i > (-1); i--) {
    while (!st.empty() && a[i] <= a[st.top()]) st.pop();
    if (st.empty())
      r[i] = n;
    else
      r[i] = st.top();
    st.push(i);
  }
  int p = 0;
  for (long long i = (0); i < (n); i++) {
    p = r[i] - l[i] - 2;
    result[p] = max(a[i], result[p]);
  }
  for (long long i = (n - 2); i > (-1); i--)
    result[i] = max(result[i], result[i + 1]);
  for (long long i = (0); i < (n); i++) printf("%d ", result[i]);
  cout << endl;
  return 0;
}
