#include <bits/stdc++.h>
using namespace std;
int n, arr[200005], l[200005], r[200005], ans[200005];
stack<int> p;
void calcule() {
  for (int i = 1; i <= n; i++) {
    while (!p.empty() && arr[p.top()] >= arr[i]) {
      p.pop();
    }
    if (p.empty()) {
      l[i] = 0;
    } else {
      l[i] = p.top();
    }
    p.push(i);
  }
  while (!p.empty()) p.pop();
  for (int i = n; i >= 1; i--) {
    while (!p.empty() && arr[p.top()] >= arr[i]) {
      p.pop();
    }
    if (p.empty()) {
      r[i] = n + 1;
    } else {
      r[i] = p.top();
    }
    p.push(i);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  calcule();
  for (int i = 1; i <= n; i++) {
    ans[r[i] - l[i] - 1] = max(ans[r[i] - l[i] - 1], arr[i]);
  }
  for (int i = n - 1; i >= 0; i--) {
    ans[i] = max(ans[i], ans[i + 1]);
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << ' ';
  }
  cout << endl;
  return 0;
}
