#include <bits/stdc++.h>
using namespace std;
int A[200005];
int S[200005];
int l[200005];
int r[200005];
int main() {
  int i, n, top;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> A[i];
    l[i] = -1;
    r[i] = n;
  }
  top = -1;
  for (i = 0; i < n; i++) {
    while (top >= 0 && A[S[top]] >= A[i]) top--;
    if (top >= 0) l[i] = S[top];
    S[++top] = i;
  }
  top = -1;
  for (i = n - 1; i >= 0; i--) {
    while (top >= 0 && A[S[top]] >= A[i]) top--;
    if (top >= 0) r[i] = S[top];
    S[++top] = i;
  }
  for (i = 0; i < n; i++) S[i] = 0;
  for (i = 0; i < n; i++) {
    if (S[r[i] - l[i] - 1] < A[i]) S[r[i] - l[i] - 1] = A[i];
  }
  for (i = n; i > 0; i--) {
    if (S[i] < S[i + 1]) S[i] = S[i + 1];
  }
  for (i = 1; i <= n; i++) cout << S[i] << " ";
  return 0;
}
