#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[n + 1], l[n + 1], r[n + 1], ans[n + 2];
  for (int i = 1; i <= n; i++) cin >> a[i];
  stack<long long> s, t;
  for (int i = 1; i <= n; i++) {
    while (!s.empty() && a[s.top()] >= a[i]) s.pop();
    if (s.empty())
      l[i] = 0;
    else
      l[i] = s.top();
    s.push(i);
  }
  for (int i = n; i >= 1; i--) {
    while (!t.empty() && a[t.top()] >= a[i]) t.pop();
    if (t.empty())
      r[i] = n + 1;
    else
      r[i] = t.top();
    t.push(i);
  }
  fill(ans, ans + n + 2, 0);
  for (int i = 1; i <= n; i++) {
    int p = r[i] - l[i] - 1;
    ans[p] = max(ans[p], a[i]);
  }
  for (int i = n; i >= 1; i--) {
    ans[i] = max(ans[i + 1], ans[i]);
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
