#include <bits/stdc++.h>
using namespace std;
long long n;
long long arr[200005];
long long rt[200005], sizee[200005];
long long mark[200005];
long long maxsize = 0;
long long root(long long i) {
  while (rt[i] != i) {
    rt[i] = rt[rt[i]];
    i = rt[i];
  }
  return i;
}
void merge(long long A, long long B) {
  long long root_A = root(A);
  long long root_B = root(B);
  if (rt[root_A] == rt[root_B]) return;
  if (sizee[root_A] < sizee[root_B]) {
    rt[root_A] = rt[root_B];
    sizee[root_B] += sizee[root_A];
  } else {
    rt[root_B] = rt[root_A];
    sizee[root_A] += sizee[root_B];
  }
  maxsize = max(maxsize, sizee[root_A]);
  maxsize = max(maxsize, sizee[root_B]);
}
int32_t main() {
  cin >> n;
  set<long long> hs;
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) rt[i] = i, sizee[i] = 1;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    hs.insert(arr[i]);
  }
  long long ct = 0;
  for (auto i : hs) mp[i] = ++ct;
  vector<long long> v[ct + 2];
  for (long long i = 0; i < n; i++) v[mp[arr[i]]].push_back(i);
  long long currval = 0;
  long long ind = ct;
  for (long long i = 1; i <= n; i++) {
    while (maxsize < i) {
      for (long long j : v[ind]) {
        if (j != n - 1 && mark[j + 1]) merge(j, j + 1);
        if (j != 0 && mark[j - 1]) merge(j, j - 1);
        mark[j] = 1;
        maxsize = max(maxsize, 1ll);
      }
      ind--;
    }
    cout << arr[v[ind + 1][0]] << " ";
  }
}
