#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N], L[N], R[N], ans[N];
stack<int> s, t;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    while (s.size() && a[i] <= a[s.top()]) s.pop();
    if (s.empty())
      L[i] = -1;
    else
      L[i] = s.top();
    s.push(i);
  }
  for (int i = n - 1; i > -1; i--) {
    while (t.size() && a[i] <= a[t.top()]) t.pop();
    if (t.empty())
      R[i] = n;
    else
      R[i] = t.top();
    t.push(i);
  }
  for (int i = 0; i < n; i++)
    ans[R[i] - L[i] - 1] = max(ans[R[i] - L[i] - 1], a[i]);
  for (int i = n; i > 0; i--) ans[i] = max(ans[i], ans[i + 1]);
  for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
  return 0;
}
