#include <bits/stdc++.h>
using namespace std;
const long long infl = 1e18 + 5;
long long n, m, k, q, x, y, f, val, t, i, j;
long long ind, cnt, sz, sm, mx, mn;
long long a[1000004], r[1000004], l[1000004], ans[1000004];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  if (fopen("inp.txt", "r")) {
    freopen("myfile.txt", "w", stdout);
    freopen("inp.txt", "r", stdin);
  }
  cin >> n;
  mn = infl;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    mn = min(mn, a[i]);
  }
  stack<long long> st;
  for (i = 0; i < n; i++) {
    while (!st.empty() && a[st.top()] > a[i]) {
      r[st.top()] = i;
      st.pop();
    }
    st.push(i);
  }
  while (!st.empty()) {
    r[st.top()] = n;
    st.pop();
  }
  for (i = n - 1; i >= 0; i--) {
    while (!st.empty() && a[st.top()] > a[i]) {
      l[st.top()] = i;
      st.pop();
    }
    st.push(i);
  }
  while (!st.empty()) {
    l[st.top()] = -1;
    st.pop();
  }
  for (i = 0; i < n; i++) {
    long long len = r[i] - l[i] - 1;
    ans[len] = max(ans[len], a[i]);
  }
  ans[n] = mn;
  for (i = n - 1; i >= 1; i--) {
    ans[i] = max(ans[i], ans[i + 1]);
  }
  for (i = 1; i < n + 1; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
