#include <bits/stdc++.h>
using namespace std;
const int MaxN = (int)(2e5) + 128;
int a[MaxN], l[MaxN], r[MaxN], d[MaxN];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  vector<pair<int, int> > v;
  v.push_back(make_pair(1, a[1]));
  l[1] = 1;
  r[n] = n;
  for (int i = 2; i <= n; ++i) {
    pair<int, int> p = make_pair(i, a[i]);
    while (!v.empty() && v.back().second >= p.second) {
      p.first = min(p.first, v.back().first);
      v.pop_back();
    }
    v.push_back(p);
    l[i] = p.first;
  }
  v.clear();
  v.push_back(make_pair(n, a[n]));
  for (int i = n - 1; i >= 1; --i) {
    pair<int, int> p = make_pair(i, a[i]);
    while (!v.empty() && v.back().second >= p.second) {
      p.first = max(p.first, v.back().first);
      v.pop_back();
    }
    v.push_back(p);
    r[i] = p.first;
  }
  for (int i = 1; i <= n; ++i) {
    int x = l[i], y = r[i];
    d[y - x + 1] = max(d[y - x + 1], a[i]);
  }
  for (int i = n; i >= 1; --i) d[i] = max(d[i + 1], d[i]);
  for (int i = 1; i <= n; ++i) {
    cout << d[i] << " ";
  }
  return 0;
}
