#include <bits/stdc++.h>
using namespace std;
long long n, Arr[500007], Parent[500007], Dp[500007], Idx, Len[500007];
pair<long long, long long> Pair[500007];
long long Find_Parent(long long x) {
  if (Parent[x] == x) return x;
  return Parent[x] = Find_Parent(Parent[x]);
}
void DSU(long long u, long long v) {
  if (Find_Parent(u) == Find_Parent(v)) return;
  long long x = Len[Find_Parent(u)] + Len[Find_Parent(v)];
  Dp[x] = max(Dp[x], min(Arr[u], Arr[v]));
  Parent[Find_Parent(u)] = Find_Parent(v);
  Len[Find_Parent(v)] = x;
}
bool Compare(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first > b.first;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0; i < 500007; ++i) Parent[i] = i, Len[i] = 1;
  for (long long i = 1; i <= n; ++i) cin >> Arr[i], Pair[i] = {Arr[i], i};
  sort(Pair + 1, Pair + 1 + n, Compare);
  for (long long i = 1; i <= n; ++i) {
    Idx = Pair[i].second;
    if (Arr[Idx - 1] >= Pair[i].first && Arr[Idx + 1] >= Pair[i].first &&
        Idx > 1 && Idx < n)
      DSU(Idx, Idx - 1), DSU(Idx, Idx + 1);
    else if (Arr[Idx - 1] >= Pair[i].first && Idx > 1)
      DSU(Idx, Idx - 1);
    else if (Arr[Idx + 1] >= Pair[i].first && Idx < n)
      DSU(Idx, Idx + 1);
    else
      Dp[1] = max(Dp[1], Arr[Idx]);
  }
  for (long long len = n; len >= 1; --len) Dp[len] = max(Dp[len], Dp[len + 1]);
  for (long long len = 1; len <= n; ++len) cout << Dp[len] << " ";
  return 0;
}
