#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
const long long int N = 1e5;
void JAISHREERAM() {
  long long int n, i, j, ans = 0;
  cin >> n;
  vector<pair<long long int, long long int>> a(n, {0, 1});
  for (long long int i = 0; i < n; i++) cin >> a[i].first;
  stack<pair<long long int, long long int>> st;
  st.push({0, -1});
  for (long long int i = 0; i < n; i++) {
    while (st.top().first >= a[i].first) st.pop();
    a[i].second += i - st.top().second - 1;
    st.push({a[i].first, i});
  }
  while (st.size()) st.pop();
  st.push({0, n});
  for (i = n - 1; i >= 0; i--) {
    while (st.top().first >= a[i].first) st.pop();
    a[i].second += st.top().second - i - 1;
    st.push({a[i].first, i});
  }
  sort(a.rbegin(), a.rend());
  vector<long long int> res(n, -1);
  int p = 0;
  for (i = 0; i < n && p < n; i++) {
    for (j = p; j < a[i].second && p < n; j++) res[p++] = a[i].first;
  }
  for (auto x : res) cout << x << " ";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int T = 1;
  for (int t = 1; t <= T; t++) {
    JAISHREERAM();
  }
  return 0;
}
