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