#include <bits/stdc++.h>
using namespace std;
template <class T>
string ToString(T t) {
  stringstream s;
  s << t;
  return s.str();
}
template <class T>
void ToOther(T &t, string a) {
  stringstream s(a);
  s >> t;
}
int n;
int a[200005];
int S[200005];
int E[200005];
struct SegTree {
  struct node {
    int s, e;
    long long sum, ck;
    node() {}
    node(int _s, int _e, long long _sum, long long _ck) {
      s = _s;
      e = _e;
      sum = _sum;
      ck = _ck;
    }
  } tre[1 << 20];
  void init(int n) { make(0, n - 1, 0); }
  void make(int s, int e, int k) {
    tre[k] = node(s, e, 0, 0);
    if (s == e) {
      tre[k] = node(s, e, 0, 0);
    } else
      make(s, (s + e) / 2, k * 2 + 1), make((s + e) / 2 + 1, e, k * 2 + 2),
          up(k);
  }
  void push_down(int k) {
    long long &t = tre[k].ck;
    if (!t) return;
    tre[k].sum = max(tre[k].sum, t);
    if (tre[k].s != tre[k].e) {
      tre[k * 2 + 1].ck = max(tre[k * 2 + 1].ck, t);
      tre[k * 2 + 2].ck = max(tre[k * 2 + 2].ck, t);
    }
    t = 0;
  }
  void up(int k) {
    if (tre[k].s != tre[k].e)
      tre[k].sum = max(tre[k * 2 + 1].sum, tre[k * 2 + 2].sum);
  }
  long long read(int L, int R, int k = 0) {
    push_down(k);
    if (R < tre[k].s || tre[k].e < L) return 0;
    if (L <= tre[k].s && tre[k].e <= R) return tre[k].sum;
    return max(read(L, R, k * 2 + 1), read(L, R, k * 2 + 2));
  }
  void up(int L, int R, int v, int k = 0) {
    push_down(k);
    if (R < tre[k].s || tre[k].e < L)
      ;
    else if (L <= tre[k].s && tre[k].e <= R)
      tre[k].ck = max(tre[k].ck, (long long)v), push_down(k);
    else
      up(L, R, v, k * 2 + 1), up(L, R, v, k * 2 + 2), up(k);
  }
} seg;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  stack<pair<int, int> > st;
  st.push(pair<int, int>(0, -1));
  for (int i = 0; i < n; i++) {
    while (st.top().first >= a[i]) st.pop();
    S[i] = st.top().second + 1;
    if (st.top().first != a[i]) st.push(pair<int, int>(a[i], i));
  }
  while (st.size()) st.pop();
  st.push(pair<int, int>(0, n));
  for (int i = n - 1; i >= 0; i--) {
    while (st.top().first >= a[i]) st.pop();
    E[i] = st.top().second - 1;
    if (st.top().first != a[i]) st.push(pair<int, int>(a[i], i));
  }
  seg.init(n);
  for (int i = 0; i < n; i++) seg.up(0, E[i] - S[i], a[i]);
  for (int i = 0; i < n; i++) printf("%d ", seg.read(i, i));
}
