#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int MAX = 2e5 + 5;
const long long MAX2 = 11;
const long long MOD = 1000000007;
const long long INF = 2e18;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 450;
int n, x[MAX], ans[MAX], le[MAX], ri[MAX], dv;
stack<pair<int, int> > s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> x[i];
  for (int i = 1; i <= n; ++i) {
    while (!s.empty() && s.top().first > x[i]) ri[s.top().second] = i, s.pop();
    s.push({x[i], i});
  }
  while (!s.empty()) ri[s.top().second] = n + 1, s.pop();
  for (int i = n; i >= 1; --i) {
    while (!s.empty() && s.top().first > x[i]) le[s.top().second] = i, s.pop();
    s.push({x[i], i});
  }
  while (!s.empty()) le[s.top().second] = 0, s.pop();
  for (int i = 1; i <= n; ++i) {
    dv = ri[i] - le[i] - 1;
    ans[dv] = max(ans[dv], x[i]);
  }
  for (int i = n; i >= 1; --i) ans[i] = max(ans[i], ans[i + 1]);
  for (int i = 1; i <= n; ++i) cout << ans[i] << ' ';
  cout << "\n";
  return 0;
}
