#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target( \
    "fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '{';
  string sep;
  for (const auto &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr) {
  os << '{';
  string sep;
  for (const auto &x : arr) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << ' ' << H;
  debug_out(T...);
}
class DisjointSet {
  vector<int> par;
  vector<int> size;
  int max_size;

 public:
  DisjointSet(int n) {
    par = size = vector<int>(n + 5);
    for (int i = 0; i < n + 5; i++) {
      size[i] = 1;
      par[i] = i;
    }
    max_size = 1;
  }
  int root(int x) {
    while (x != par[x]) x = par[x];
    return x;
  }
  void join(int a, int b) {
    a = root(a);
    b = root(b);
    if (a == b) return;
    if (size[a] < size[b]) swap(a, b);
    size[a] += size[b];
    par[b] = a;
    max_size = max(max_size, size[a]);
  }
  int get_max() { return max_size; }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  vector<int> comp = arr;
  sort(comp.begin(), comp.end());
  comp.erase(unique(comp.begin(), comp.end()), comp.end());
  for (auto &to : arr)
    to = lower_bound(comp.begin(), comp.end(), to) - comp.begin();
  vector<vector<int>> where(n);
  for (int i = 0; i < n; i++) where[arr[i]].emplace_back(i);
  DisjointSet DSU(n);
  int cur = 0;
  vector<bool> is_ok(n, false);
  vector<int> ans(n);
  for (int i = (int)comp.size() - 1; ~i; i--) {
    for (auto add : where[i]) {
      is_ok[add] = true;
      if (add + 1 < n && is_ok[add + 1]) DSU.join(add, add + 1);
      if (add - 1 >= 0 && is_ok[add - 1]) DSU.join(add, add - 1);
    }
    const int elem = comp[i];
    const int best = DSU.get_max();
    while (cur < best) {
      ans[cur] = elem;
      ++cur;
    }
  }
  for (auto to : ans) cout << to << ' ';
  cout << '\n';
  return 0;
}
