#include <bits/stdc++.h>
using namespace std;
long long i, i1, i2, j, j2, k, t, a[10000000], p, d, c1, c2, d1, d2, e1, pas1,
    pas2, e2, pmx, l[1000000], r[1000000], m, n, fx1[1000001], fx2[1000001], mx,
    mmx[10000], mn, cnt, c, e, x, y, h1, h2, x1, x2, yy1, y2, n1, n2;
vector<long long> v;
pair<long long, long long> b[1000];
string s1, s2, ss[10000];
long long pas[1000000];
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  stack<int> s;
  for (i = 1; i <= n; i++) {
    while (!s.empty() && a[s.top()] >= a[i]) s.pop();
    if (s.empty())
      l[i] = 0;
    else
      l[i] = s.top();
    s.push(i);
  }
  while (!s.empty()) s.pop();
  for (i = n; i >= 1; i--) {
    while (!s.empty() && a[s.top()] >= a[i]) s.pop();
    if (s.empty())
      r[i] = n + 1;
    else
      r[i] = s.top();
    s.push(i);
  }
  for (i = 1; i <= n + 1; i++) {
    pas[r[i] - l[i] - 1] = max(pas[r[i] - l[i] - 1], a[i]);
  }
  for (i = n; i > 0; i--) pas[i] = max(pas[i], pas[i + 1]);
  for (i = 1; i <= n; i++) cout << pas[i] << " ";
  return 0;
}
