#include <bits/stdc++.h>
using namespace std;
const int N = 2E5 + 50;
int n;
int ans[N], a[N];
int l[N], r[N];
int s[N], top;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  top = 0;
  s[0] = 0;
  for (int i = 1; i <= n; i++) {
    while (top > 0 && a[i] <= a[s[top]]) {
      top--;
    }
    l[i] = s[top];
    s[++top] = i;
  }
  top = 0;
  s[0] = n + 1;
  for (int i = n; i >= 1; i--) {
    while (top > 0 && a[i] <= a[s[top]]) {
      top--;
    }
    r[i] = s[top];
    s[++top] = i;
  }
  for (int i = 1; i <= n; i++) {
    int len = r[i] - l[i] - 1;
    ans[len] = max(ans[len], a[i]);
  }
  for (int i = n; i >= 1; i--) {
    ans[i] = max(ans[i], ans[i + 1]);
  }
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
