#include <bits/stdc++.h>
using namespace std;
vector<int> Left, Right;
void build(vector<int>& A) {
  Left.resize(A.size());
  Right.resize(A.size());
  stack<int> S;
  S.push(0);
  for (int i = 1; i < A.size(); i++) {
    int x = S.top();
    if (A[i] >= A[x])
      S.push(i);
    else {
      while (!S.empty() && A[S.top()] > A[i]) {
        Right[S.top()] = i;
        S.pop();
      }
      S.push(i);
    }
  }
  while (!S.empty()) {
    Right[S.top()] = A.size();
    S.pop();
  }
  S.push(A.size() - 1);
  for (int i = A.size() - 2; i >= 0; i--) {
    int x = S.top();
    if (A[i] >= A[x])
      S.push(i);
    else {
      while (!S.empty() && A[S.top()] > A[i]) {
        Left[S.top()] = i;
        S.pop();
      }
      S.push(i);
    }
  }
  while (!S.empty()) {
    Left[S.top()] = -1;
    S.pop();
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) cin >> A[i];
  build(A);
  vector<int> Ans(n);
  Ans.assign(n, -1);
  for (int i = 0; i < n; i++)
    Ans[Right[i] - Left[i] - 1 - 1] =
        std::max(Ans[Right[i] - Left[i] - 1 - 1], A[i]);
  for (int i = n - 2; i >= 0; i--) Ans[i] = max(Ans[i], Ans[i + 1]);
  for (auto x : Ans) cout << x << " ";
}
