#include <bits/stdc++.h>
using namespace std;
vector<int> p(2 * (1 << 18), 0);
vector<int> s(2 * (1 << 18), 0);
vector<int> m(2 * (1 << 18), 0);
void muuta(int k) {
  k += (1 << 18);
  p[k] = 1;
  s[k] = 1;
  m[k] = 1;
  int ss = 1;
  for (k /= 2; k >= 1; k /= 2) {
    p[k] = max(p[2 * k], m[2 * k] == ss ? m[2 * k] + p[2 * k + 1] : 0);
    s[k] = max(s[2 * k + 1], m[2 * k + 1] == ss ? m[2 * k + 1] + s[2 * k] : 0);
    m[k] = max(m[2 * k], max(m[2 * k + 1],
                             max(s[2 * k] + p[2 * k + 1], max(p[k], s[k]))));
    ss *= 2;
  }
}
int main() {
  int n;
  cin >> n;
  int a[202020];
  vector<int> b;
  unordered_set<int> u;
  unordered_map<int, vector<int> > mm;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (u.count(a[i]) == 0) b.push_back(a[i]);
    mm[a[i]].push_back(i);
    u.insert(a[i]);
  }
  sort(b.begin(), b.end());
  int p = b.size() - 1;
  for (auto f : mm[b[p]]) muuta(f);
  cout << b[p] << " ";
  for (int i = 2; i <= n; i++) {
    int mmm = max(m[1], m[0]);
    while (mmm < i) {
      p--;
      if (p < 0) {
        p = 0;
        break;
      }
      for (auto f : mm[b[p]]) muuta(f);
      mmm = max(m[1], m[0]);
    }
    cout << b[p] << " ";
  }
  cout << endl;
  return 0;
}
