#include <bits/stdc++.h>
using namespace std;
long long int fast_exp(long long int A, long long int B, long long int C) {
  if (A == 0) return 0;
  if (C == 0) return 0;
  if (B == 0) return 1;
  if (B == 1) return A % C;
  long long int res = A;
  if (res > C) res = res % C;
  int counter = 2;
  while (counter < B) {
    res = res * res;
    if (res > C) res = res % C;
    counter *= 2;
    if (counter >= B) break;
  }
  counter /= 2;
  return ((res % C) * fast_exp(A, B - counter, C)) % C;
}
long long int mod_add(long long int a, long long int b, long long int m) {
  return (a + b) % m;
}
long long int subtract(long long int a, long long int b, long long int m) {
  return ((a - b) % m + m) % m;
}
long long int multiply(long long int a, long long int b, long long int m) {
  return (a * b) % m;
}
long long int divide(long long int a, long long int b, long long int m) {
  return (a * fast_exp(b, m - 2, m)) % m;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> A;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    A.push_back(x);
  };
  stack<long long int> st;
  vector<long long int> dp(n, -1);
  st.push(0);
  for (long long int i = 1; i < n; i += 1) {
    while (not st.empty()) {
      if (A[st.top()] >= A[i])
        st.pop();
      else
        break;
    }
    if (not st.empty()) dp[i] = st.top();
    st.push(i);
  }
  while (not st.empty()) st.pop();
  st.push(n - 1);
  vector<long long int> dp1(n, -1);
  for (long long int i = n - 2; i >= 0; i--) {
    while (not st.empty()) {
      if (A[st.top()] >= A[i])
        st.pop();
      else
        break;
    }
    if (not st.empty()) dp1[i] = st.top();
    st.push(i);
  }
  map<long long int, long long int> mp;
  for (long long int i = 0; i < n; i += 1) {
    if (dp[i] != -1 and dp1[i] != -1) {
      if (mp.find(A[i]) != mp.end()) {
        mp[A[i]] = max(mp[A[i]], dp1[i] - dp[i] - 1);
      } else {
        mp[A[i]] = dp1[i] - dp[i] - 1;
      }
    } else if (dp[i] == -1 and dp1[i] != -1) {
      long long int temp = dp1[i];
      if (mp.find(A[i]) != mp.end()) {
        mp[A[i]] = max(mp[A[i]], temp);
      } else
        mp[A[i]] = temp;
    } else if (dp[i] != -1 and dp1[i] == -1) {
      long long int temp = n - 1 - dp[i];
      if (mp.find(A[i]) != mp.end()) {
        mp[A[i]] = max(mp[A[i]], temp);
      } else
        mp[A[i]] = temp;
    } else {
      long long int temp = n;
      if (mp.find(A[i]) != mp.end()) {
        mp[A[i]] = max(mp[A[i]], temp);
      } else
        mp[A[i]] = temp;
    }
  }
  long long int start = 0;
  long long int done_until = -1;
  auto it = mp.rbegin();
  for (auto it = mp.rbegin(); it != mp.rend(); it++) {
    if (done_until < it->second - 1) {
      while (done_until < it->second - 1) {
        cout << it->first << " ";
        done_until++;
      }
    }
  }
  return 0;
}
