#include <bits/stdc++.h>
using namespace std;
stack<int> s, s2;
int a[200010], l[200010], r[200010], ans[200010];
int main() {
  int n, i;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  i = 1;
  while (i <= n) {
    while (!s.empty() && a[s.top()] >= a[i]) s.pop();
    if (!s.empty()) {
      l[i] = s.top();
    } else {
      l[i] = 0;
    }
    s.push(i);
    i++;
  }
  i = n;
  while (i >= 1) {
    while (!s2.empty() && a[s2.top()] >= a[i]) s2.pop();
    if (!s2.empty())
      r[i] = s2.top();
    else {
      r[i] = n + 1;
    }
    s2.push(i);
    i--;
  }
  for (i = 1; i <= n; i++) {
    ans[r[i] - l[i] - 1] = max(ans[r[i] - l[i] - 1], a[i]);
  }
  for (i = n - 1; i >= 1; i--) {
    ans[i] = max(ans[i + 1], ans[i]);
  }
  for (i = 1; i <= n; i++) cout << ans[i] << " ";
}
