#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int l[N], r[N], a[N], n, dp[2 * N];
stack<int> cur;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int best = 0;
  for (int i = 0; i < n; i++) {
    while (!cur.empty() && a[cur.top()] >= a[i]) {
      best = cur.top();
      cur.pop();
    }
    best = i;
    if (!cur.empty()) {
      best = cur.top() + 1;
    } else {
      best = 0;
    }
    l[i] = best;
    cur.push(i);
  }
  while (!cur.empty()) cur.pop();
  for (int i = n - 1; i >= 0; i--) {
    while (!cur.empty() && a[cur.top()] >= a[i]) {
      best = cur.top();
      cur.pop();
    }
    best = i;
    if (!cur.empty()) {
      best = cur.top() - 1;
    } else {
      best = n - 1;
    }
    r[i] = best;
    cur.push(i);
  }
  for (int i = 0; i < n; i++) {
    int len = r[i] - l[i] + 1;
    dp[len] = max(dp[len], a[i]);
  }
  for (int i = n; i >= 1; i--) {
    dp[i] = max(dp[i], dp[i + 1]);
  }
  for (int i = 1; i <= n; i++) {
    if (i > 1) printf(" ");
    printf("%d", dp[i]);
  }
  puts("");
  return 0;
}
