#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O2")
const int LIM = 2e5 + 1, inf = INT_MAX;
int n, nAdjusted, size;
int h[LIM], l[LIM], r[LIM];
int a[LIM], segtree[4 * LIM], update[4 * LIM];
int nextPowerOf2(int i) {
  int ans = 1;
  while (ans < i) ans *= 2;
  return ans;
}
void rangeUpdate(int curNode, int leftCur, int rightCur, int l, int r,
                 int val) {
  if (l > r) return;
  if (l == leftCur && r == rightCur) {
    if (val > segtree[curNode]) {
      segtree[curNode] = val;
      update[curNode] = val;
    } else
      update[curNode] = val;
    return;
  }
  int mid = (leftCur + rightCur) / 2;
  if (update[curNode] != -1) {
    update[2 * curNode] = update[curNode];
    segtree[2 * curNode] = max(segtree[2 * curNode], segtree[curNode]);
    update[2 * curNode + 1] = update[curNode];
    segtree[2 * curNode + 1] = max(segtree[2 * curNode + 1], segtree[curNode]);
    update[curNode] = -1;
  }
  if (l > mid)
    rangeUpdate(2 * curNode + 1, mid + 1, rightCur, l, r, val);
  else if (r <= mid)
    rangeUpdate(2 * curNode, leftCur, mid, l, r, val);
  else {
    rangeUpdate(2 * curNode, leftCur, mid, l, mid, val);
    rangeUpdate(2 * curNode + 1, mid + 1, rightCur, mid + 1, r, val);
  }
}
int atIndex(int i, int curNode = 1, int leftCur = 1, int rightCur = nAdjusted) {
  if (leftCur == rightCur) return segtree[curNode];
  if (update[curNode] != -1) {
    update[2 * curNode] = update[curNode];
    segtree[2 * curNode] = max(segtree[2 * curNode], segtree[curNode]);
    update[2 * curNode + 1] = update[curNode];
    segtree[2 * curNode + 1] = max(segtree[2 * curNode + 1], segtree[curNode]);
    update[curNode] = -1;
  }
  int mid = (leftCur + rightCur) / 2;
  if (i <= mid)
    return atIndex(i, 2 * curNode, leftCur, mid);
  else
    return atIndex(i, 2 * curNode + 1, mid + 1, rightCur);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i < n + 1; i++) cin >> h[i];
  nAdjusted = nextPowerOf2(n);
  size = 2 * nAdjusted - 1;
  for (int i = 1; i < size + 1; i++) {
    segtree[i] = 0;
    update[i] = -1;
  }
  stack<int> s;
  for (int i = 1; i < n + 1; i++) {
    while (!s.empty() && h[s.top()] >= h[i]) s.pop();
    if (s.empty())
      l[i] = 0;
    else
      l[i] = s.top();
    s.push(i);
  }
  stack<int> s1;
  for (int i = n; i >= 1; i--) {
    while (!s1.empty() && h[s1.top()] >= h[i]) s1.pop();
    if (s1.empty())
      r[i] = n + 1;
    else
      r[i] = s1.top();
    s1.push(i);
  }
  for (int i = 1; i < n + 1; i++) {
    rangeUpdate(1, 1, nAdjusted, 1, r[i] - l[i] - 1, h[i]);
  }
  for (int i = 1; i < n + 1; i++) cout << atIndex(i) << " ";
  cout << "\n";
  return 0;
}
