#include <bits/stdc++.h>
using namespace std;
const long long N = 312345;
long long ar[N];
long long ans[N];
long long l[N], r[N];
inline void pre() {}
void solve() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; ++i) cin >> ar[i];
  stack<long long> stk;
  stk.push(n + 1);
  for (long long i = n; i > 0; --i) {
    while (ar[stk.top()] >= ar[i]) {
      stk.pop();
    }
    r[i] = stk.top() - 1;
    stk.push(i);
  }
  while (stk.size() > 0) stk.pop();
  stk.push(0);
  for (long long i = 1; i <= n; ++i) {
    while (ar[i] <= ar[stk.top()]) stk.pop();
    l[i] = stk.top() + 1;
    stk.push(i);
  }
  for (long long i = 1; i <= n; ++i) {
    ans[r[i] - l[i] + 1] = max(ans[r[i] - l[i] + 1], ar[i]);
  }
  for (long long i = n - 1; i > 0; --i) {
    ans[i] = max(ans[i + 1], ans[i]);
  }
  for (long long i = 1; i <= n; ++i) cout << ans[i] << " ";
  cout << "\n";
}
int main() {
  pre();
  int t = 1;
  for (int z = 0; z < t; ++z) solve();
  return 0;
}
