#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<long long> l(n + 1, 0);
  vector<long long> r(n + 1, 0);
  stack<long long> q;
  for (int i = 1; i <= n; i++) {
    while (q.size() != 0 && a[q.top()] > a[i]) {
      q.pop();
    }
    if (q.size() == 0) {
      l[i] = 0;
    } else {
      if (a[q.top()] == a[i])
        l[i] = l[q.top()];
      else
        l[i] = q.top();
    }
    q.push(i);
  }
  stack<long long> w;
  for (int i = n; i > 0; i--) {
    while (w.size() != 0 && a[w.top()] > a[i]) {
      w.pop();
    }
    if (w.size() == 0) {
      r[i] = 0;
    } else {
      if (a[w.top()] == a[i])
        r[i] = r[w.top()];
      else
        r[i] = w.top();
    }
    w.push(i);
  }
  vector<long long> ans(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    long long len = 1;
    if (r[i] == 0 && l[i] == 0) {
      len = n;
    } else {
      if (r[i] == 0) len = n - l[i];
      if (l[i] == 0) len = r[i] - 1;
      if (l[i] != 0 && r[i] != 0) len = r[i] - l[i] - 1;
    }
    long long one = 1;
    len = max(len, one);
    ans[len] = max(ans[len], a[i]);
  }
  long long mins = 1000000001;
  for (int i = 1; i <= n; i++) mins = min(a[i], mins);
  ans[n] = mins;
  for (int i = n - 1; i >= 1; i--) {
    ans[i] = max(ans[i], ans[i + 1]);
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
