#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int N = 2e5 + 1;
bool vis[N];
int ans[N];
int mxm;
int low;
int n;
pair<int, int> h[N];
struct Dsu {
  int par[N];
  int cnt[N];
} dsu;
int getint() {
  char inp;
  int res = 0;
  while ((inp = getchar()) && !(inp >= '0' && inp <= '9'))
    ;
  do {
    res = res * 10 + inp - '0';
  } while ((inp = getchar()) && (inp >= '0' && inp <= '9'));
  return res;
}
void unite(int i, int j) {
  if (dsu.cnt[i] > dsu.cnt[j]) {
    dsu.cnt[i] += dsu.cnt[j];
    mxm = max(mxm, dsu.cnt[i]);
    dsu.par[j] = i;
  } else {
    dsu.cnt[j] += dsu.cnt[i];
    mxm = max(mxm, dsu.cnt[j]);
    dsu.par[i] = j;
  }
}
int findset(int i) {
  return (dsu.par[i] == i ? i : dsu.par[i] = findset(dsu.par[i]));
}
void input() {
  n = getint();
  for (int i = 1; i <= n; ++i) {
    h[i].second = i;
    dsu.par[i] = i;
    dsu.cnt[i] = 1;
    h[i].first = getint();
  }
  sort(h + 1, h + n + 1,
       [](pair<int, int> x, pair<int, int> y) { return x.first > y.first; });
}
void solve() {
  low = 1;
  mxm = 1;
  for (int i = 1; i <= n; ++i) {
    vis[h[i].second] = 1;
    if (vis[h[i].second + 1]) {
      unite(findset(h[i].second), findset(h[i].second + 1));
    }
    if (vis[h[i].second - 1]) {
      unite(findset(h[i].second), findset(h[i].second - 1));
    }
    for (int j = low; j <= mxm; ++j) {
      ans[j] = h[i].first;
    }
    low = mxm + 1;
  }
  for (int i = 1; i <= n; ++i) {
    cout << ans[i] << " ";
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  input();
  solve();
}
