#include <bits/stdc++.h>
using namespace std;
const long long MaX = 100005, infi = 1110111110111, mod = 1000000007;
const int MX = 200005;
long long n;
vector<int> org(MX);
map<long long, long long> ans, pr;
stack<long long> ST;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> org[i];
    int las = 0;
    while (ST.size() && org[ST.top()] >= org[i]) {
      ans[ST.top()] += 1 + las;
      las = ans[ST.top()];
      ST.pop();
    }
    ans[i] += las;
    ST.push(i);
  }
  int las = 0;
  while (ST.size()) {
    ans[ST.top()] += 1 + las;
    las = ans[ST.top()];
    ST.pop();
  }
  for (auto u : ans) pr[org[u.first]] = max(u.second, pr[org[u.first]]);
  sort(org.begin(), org.end(), greater<int>());
  int ptr = 0;
  for (int i = 1; i <= n; i++) {
    while (pr[org[ptr]] < i) ptr++;
    cout << org[ptr] << " ";
  }
  return 0;
}
