#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> Segm_tree(9e5, -2000000000);
void change(int l, int r, int pos, int val, int v) {
  if (pos < l || pos >= r) {
    return;
  }
  if (l == r - 1 && l == pos) {
    Segm_tree[v] = val;
    return;
  }
  int mid = (l + r) / 2;
  change(l, mid, pos, val, 2 * v + 1);
  change(mid, r, pos, val, 2 * v + 2);
  Segm_tree[v] = max(Segm_tree[2 * v + 1], Segm_tree[2 * v + 2]);
  return;
}
int get_mx(int l, int r, int tl, int tr, int v) {
  if (r <= tl || tr <= l) {
    return -2e9;
  }
  if (tl <= l && r <= tr) {
    return Segm_tree[v];
  }
  int mid = (l + r) / 2;
  return max(get_mx(l, mid, tl, tr, 2 * v + 1),
             get_mx(mid, r, tl, tr, 2 * v + 2));
}
int main() {
  cin >> n;
  vector<int> Num(n);
  set<int> Srt;
  for (int i = 0; i < n; i++) {
    cin >> Num[i];
    Srt.insert(Num[i]);
  }
  map<int, int> Conv, Rev;
  int cnt = 1;
  for (auto q : Srt) {
    Conv[q] = cnt;
    Rev[cnt++] = q;
  }
  for (int i = 0; i < n; i++) {
    Num[i] = Conv[Num[i]];
  }
  vector<int> Pos1(n), Pos2(n);
  for (int i = 0; i < n; i++) {
    Pos1[i] = get_mx(0, n, 0, Num[i], 0) + 1;
    if (Pos1[i] < -2e6) {
      Pos1[i] = 0;
    }
    change(0, n, Num[i], i, 0);
  }
  Segm_tree.assign(9e5, -2000000000);
  for (int i = n - 1; i >= 0; i--) {
    Pos2[i] = (-1) * get_mx(0, n, 0, Num[i], 0);
    if (Pos2[i] >= 2e6) {
      Pos2[i] = n;
    }
    change(0, n, Num[i], -1 * i, 0);
  }
  vector<int> Mx(cnt, 0);
  for (int i = 0; i < n; i++) {
    Mx[Num[i]] = max(Mx[Num[i]], Pos2[i] - Pos1[i]);
  }
  int cur = cnt - 1;
  for (int i = 1; i <= n; i++) {
    while (i > Mx[cur]) {
      cur--;
    }
    cout << Rev[cur] << ' ';
  }
}
