#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  stack<pair<long long, long long>> s1, s2;
  s1.push({0, -1});
  long long left[n], right[n];
  for (long long i = 0; i < n; ++i) {
    while (s1.top().first >= arr[i]) s1.pop();
    left[i] = s1.top().second + 1;
    s1.push({arr[i], i});
  }
  s2.push({0, n});
  for (long long i = n - 1; i >= 0; --i) {
    while (s2.top().first >= arr[i]) s2.pop();
    right[i] = s2.top().second - 1;
    s2.push({arr[i], i});
  }
  long long ans[n + 1];
  memset(ans, 0, sizeof(ans));
  for (long long i = 0; i < n; ++i) {
    ans[right[i] - left[i] + 1] = max(arr[i], ans[right[i] - left[i] + 1]);
  }
  for (long long i = n - 1; i >= 1; --i) {
    if (ans[i] < ans[i + 1]) ans[i] = ans[i + 1];
  }
  for (long long i = 0; i < n; ++i) {
    cout << ans[i + 1] << " ";
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
