#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  int q = 0;
  scanf("%d", &n);
  vector<long long int> a(n);
  vector<int> left(n);
  vector<int> right(n);
  for (int i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  left[0] = 0;
  for (int i = 1; i < n; i++) {
    q = 1;
    while (i - q >= 0 && a[i - q] >= a[i]) {
      q += left[i - q] + 1;
    }
    left[i] = q - 1;
  }
  right[n - 1] = 0;
  for (int i = n - 2; i >= 0; i--) {
    q = 1;
    while (i + q < n && a[i + q] >= a[i]) {
      q += right[i + q] + 1;
    }
    right[i] = q - 1;
  }
  vector<int> res(n, 0);
  for (int i = 0; i < n; i++) {
    q = right[i] + left[i];
    res[q] = res[q] > a[i] ? res[q] : a[i];
  }
  q = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (res[i] > q) {
      q = res[i];
    } else {
      res[i] = q;
    }
  }
  for (int i = 0; i < n; i++) {
    printf("%d ", res[i]);
  }
  return 0;
}
