#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int path[N], region[N];
bool mark[N];
int findUnion(int x) {
  if (path[x] == x) return x;
  return path[x] = findUnion(path[x]);
}
void mergeUnion(int x, int y) {
  int u = findUnion(x), v = findUnion(y);
  if (region[u] < region[v]) swap(u, v);
  path[u] = v;
  region[v] += region[u];
}
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int> > v(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> v[i].first;
    v[i].second = i;
  }
  iota(path, path + n + 2, 0);
  fill(region + 1, region + n + 2, 1);
  sort(v.rbegin(), v.rend());
  int idx = 0;
  for (int i = 0; i < n; i++) {
    int val = v[i].first, pos = v[i].second;
    mark[pos] = true;
    if (mark[pos - 1]) mergeUnion(pos, pos - 1);
    if (mark[pos + 1]) mergeUnion(pos, pos + 1);
    int mx = region[findUnion(pos)];
    while (idx < mx) {
      cout << val << " ";
      ++idx;
    }
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tc = 1;
  while (tc--) {
    solve();
  }
  return 0;
}
