#include <bits/stdc++.h>
using namespace std;
const int N = 2E5 + 7;
int n, ans[N], l[N], r[N];
struct Q {
  int num, len;
} q[N];
bool cmp(Q a, Q b) {
  if (a.num > b.num) return true;
  return false;
}
int main() {
  cin >> n;
  memset(ans, 0, sizeof(ans));
  for (int i = 1; i <= n; i++) scanf("%d", &q[i].num);
  for (int i = 1; i <= n; i++) {
    q[i].len = 1;
    l[i] = i;
    r[i] = i;
  }
  for (int i = 1; i <= n; i++)
    while (q[l[i] - 1].num >= q[i].num) l[i] = l[l[i] - 1];
  for (int i = n; i >= 1; i--)
    while (q[r[i] + 1].num >= q[i].num) r[i] = r[r[i] + 1];
  for (int i = 1; i <= n; i++) {
    q[i].len = r[i] - l[i] + 1;
  }
  sort(q + 1, q + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    int l = q[i].len;
    while (ans[l] < q[i].num && l >= q[i - 1].len + 1) {
      ans[l] = q[i].num;
      l--;
    }
  }
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  return 0;
}
