#include <bits/stdc++.h>
using namespace std;
void debugger(long long int t) { cerr << t; }
void debugger(int t) { cerr << t; }
void debugger(string t) { cerr << t; }
void debugger(char t) { cerr << t; }
void debugger(long double t) { cerr << t; }
void debugger(double t) { cerr << t; }
void debugger(unsigned long long int t) { cerr << t; }
template <class T, class V>
void debugger(pair<T, V> p);
template <class T>
void debugger(vector<T> v);
template <class T>
void debugger(set<T> v);
template <class T, class V>
void debugger(map<T, V> v);
template <class T>
void debugger(multiset<T> v);
template <class T, class V>
void debugger(pair<T, V> p) {
  cerr << "{";
  debugger(p.first);
  cerr << ",";
  debugger(p.second);
  cerr << "}";
}
template <class T>
void debugger(vector<T> v) {
  cerr << "[ ";
  for (T i : v) {
    debugger(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void debugger(set<T> v) {
  cerr << "[ ";
  for (T i : v) {
    debugger(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void debugger(multiset<T> v) {
  cerr << "[ ";
  for (T i : v) {
    debugger(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T, class V>
void debugger(map<T, V> v) {
  cerr << "[ ";
  for (auto i : v) {
    debugger(i);
    cerr << " ";
  }
  cerr << "]";
}
long long int gcd(long long int a, long long int b) {
  if (b == 0 || a == 0) return max(a, b);
  return gcd(b, a % b);
}
const long long int N = 1e5;
void JAISHREERAM() {
  long long int n;
  cin >> n;
  vector<long long int> a(n), res(n, 1), res1(n, 1);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  stack<int> st;
  for (long long int i = 0; i < n; i++) {
    while (st.size() && a[st.top()] >= a[i]) {
      res[i] += res[st.top()];
      st.pop();
    }
    st.push(i);
  }
  while (st.size()) st.pop();
  for (int i = n - 1; i >= 0; i--) {
    while (st.size() && a[st.top()] >= a[i]) {
      res1[i] += res1[st.top()];
      st.pop();
    }
    st.push(i);
  }
  vector<long long int> ans(n, 0);
  for (long long int i = 0; i < n; i++) {
    ans[res[i] + res1[i] - 2] = max(ans[res[i] + res1[i] - 2], a[i]);
  }
  ans[n - 1] = *min_element(a.begin(), a.end());
  for (int i = n - 2; i >= 0; i--) ans[i] = max(ans[i], ans[i + 1]);
  for (auto x : ans) 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;
}
