#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long> bear(N), r(N), l(N), len(N), ans(N);
  stack<long long> roof;
  for (int i = 0; i < N; i++) cin >> bear[i];
  for (int i = N - 1; i > -1; i--) {
    while ((!roof.empty()) && (bear[roof.top()] >= bear[i])) roof.pop();
    if (roof.empty())
      r[i] = N - 1;
    else
      r[i] = roof.top() - 1;
    roof.push(i);
  }
  while (!roof.empty()) roof.pop();
  for (int i = 0; i < N; i++) {
    while (!roof.empty() && bear[roof.top()] >= bear[i]) roof.pop();
    if (roof.empty())
      l[i] = 0;
    else
      l[i] = roof.top() + 1;
    roof.push(i);
  }
  for (int i = 0; i < N; i++) {
    len[i] = r[i] - l[i] + 1;
  }
  for (int i = 0; i < N; i++) ans[i] = 0;
  for (int i = 0; i < N; i++) {
    ans[len[i] - 1] = max(bear[i], ans[len[i] - 1]);
  }
  for (int i = N - 2; i > -1; i--) {
    ans[i] = max(ans[i], ans[i + 1]);
  }
  for (int i = 0; i < N; i++) cout << ans[i] << " ";
}
