#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 10;
struct Node {
  long long height;
  long long start;
  long long pos;
  Node(int h = 0, int s = 0, int p = 0) : height(h), start(s), pos(p) {}
};
Node a[MAX_N];
long long b[MAX_N];
stack<Node> stk;
int main() {
  long long n;
  scanf("%I64d", &n);
  long long j, i, k;
  long long ans = -1;
  Node node(0, 0, 0);
  stk.push(node);
  memset(b, -1, sizeof(b));
  for (i = 1; i <= n; i++) {
    node.start = i;
    node.pos = i;
    scanf("%I64d", &node.height);
    while (stk.top().height > node.height) {
      b[i - stk.top().start] = max(b[i - stk.top().start], stk.top().height);
      node.start = stk.top().start;
      stk.pop();
    }
    stk.push(node);
  }
  while (!stk.empty()) {
    long long temp = (n - stk.top().start + 1) * stk.top().height;
    b[n - stk.top().start + 1] =
        max(b[n - stk.top().start + 1], stk.top().height);
    stk.pop();
  }
  for (i = n; i >= 1; i--) {
    b[i] = max(b[i], b[i + 1]);
  }
  for (i = 1; i <= n; i++) {
    printf("%I64d ", b[i]);
  }
}
