#include <bits/stdc++.h>
using namespace std;
stack<long long> S;
stack<long long> e;
long long n;
long long a[200005];
map<long long, vector<long long> > mp;
long long l[200005], r[200005];
long long ans[200005];
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  l[1] = 1;
  S.push(1);
  for (long long i = 2; i <= n; i++) {
    while (S.size() > 0 && a[S.top()] > a[i]) {
      l[i] = S.top();
      S.pop();
    }
    if (S.size() == 0)
      l[i] = 1;
    else
      l[i] = S.top() + 1;
    S.push(i);
  }
  S = e;
  r[n] = n;
  S.push(n);
  mp[a[n]].push_back(r[n] - l[n] + 1);
  for (long long i = n - 1; i >= 1; i--) {
    while (S.size() > 0 && a[S.top()] >= a[i]) {
      S.pop();
    }
    if (S.size() == 0)
      r[i] = n;
    else
      r[i] = S.top() - 1;
    S.push(i);
    mp[a[i]].push_back(r[i] - l[i] + 1);
  }
  long long c = 1;
  for (auto it = mp.rbegin(); it != mp.rend(); it++) {
    if (it->second.size()) {
      long long maxm = 0;
      for (auto j : it->second) maxm = max(j, maxm);
      while (c <= n && c <= maxm) {
        ans[c] = it->first;
        c++;
      }
    }
  }
  for (long long i = 1; i <= n; i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
