#include <bits/stdc++.h>
using namespace std;
void g(int &xx) {
  int x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  xx = x * f;
}
int n, a[200001], le[200001], ri[200001], ans[200001];
stack<int> s;
inline void clear() {
  while (!s.empty()) s.pop();
}
int main() {
  g(n);
  for (int i = 0; i <= 200000; ++i) le[i] = -1, ri[i] = n;
  for (int i = 0; i < n; ++i) g(a[i]);
  for (int i = 0; i < n; ++i) {
    while (!s.empty() && a[s.top()] >= a[i]) s.pop();
    if (!s.empty()) le[i] = s.top();
    s.push(i);
  }
  clear();
  for (int i = n - 1; i >= 0; --i) {
    while (!s.empty() && a[s.top()] >= a[i]) s.pop();
    if (!s.empty()) ri[i] = s.top();
    s.push(i);
  }
  for (int i = 0; i < n; ++i) {
    int lee = ri[i] - le[i] - 1;
    ans[lee] = max(ans[lee], a[i]);
  }
  for (int i = n; i >= 0; --i) ans[i] = max(ans[i], ans[i + 1]);
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  return 0;
}
