#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:667772160")
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
long long finalh[200000 + 7], h[200000 + 7];
int n;
void cal() {
  stack<long long> st;
  int i = 0, j, temp, k;
  while (i < n) {
    if (st.empty() or h[st.top()] <= h[i]) {
      st.push(i++);
      continue;
    }
    j = st.top();
    st.pop();
    k = st.empty() ? i : i - st.top() - 1;
    finalh[k] = max(finalh[k], h[j]);
  }
  while (!st.empty()) {
    j = st.top();
    st.pop();
    k = st.empty() ? n : n - st.top() - 1;
    finalh[k] = max(finalh[k], h[j]);
  }
  for (i = n - 1; i > 0; i--) finalh[i] = max(finalh[i], finalh[i + 1]);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &h[i]);
    if (i)
      finalh[n] = min(finalh[n], h[i]);
    else
      finalh[n] = h[i];
    finalh[1] = max(h[i], finalh[1]);
  }
  cal();
  for (int i = 1; i <= n; i++) {
    if (i > 1) printf(" ");
    printf("%lld", finalh[i]);
  }
  return 0;
}
