#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int getint() {
  int t = 0, flag = 1;
  char c = getchar();
  while (c < '0' || c > '9' || c == '-') {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') t = t * 10 + c - '0', c = getchar();
  return t * flag;
}
int GCD(int m, int n) { return !m ? n : GCD(n % m, m); }
template <typename T>
string to_string(T value) {
  ostringstream os;
  os << value;
  return os.str();
}
long long MultMod(long long a, long long b, long long MOD) {
  a %= MOD;
  b %= MOD;
  long long ret = 0;
  while (b) {
    if (b & 1) {
      ret += a;
      if (ret >= MOD) ret -= MOD;
    }
    a = a << 1;
    if (a >= MOD) a -= MOD;
    b = b >> 1;
  }
  return ret;
}
int a[maxn], b[maxn], n, t, m;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int l[n + 2];
  memset(l, 0, sizeof l);
  for (int i = 1; i <= n; i++) {
    int j = i - 1;
    while (a[j] >= a[i]) j = l[j];
    l[i] = j;
  }
  int r[n + 2];
  memset(r, 0, sizeof r);
  for (int i = n; i >= 1; i--) {
    int j = i + 1;
    while (a[j] >= a[i]) j = r[j];
    r[i] = j;
  }
  int dp[n + 2];
  memset(dp, 0, sizeof dp);
  for (int i = 1; i <= n; i++) {
    int len = r[i] - l[i] - 1;
    dp[len] = max(dp[len], a[i]);
  }
  for (int i = n - 1; i >= 1; i--) dp[i] = max(dp[i], dp[i + 1]);
  for (int i = 1; i <= n; i++) cout << dp[i] << " ";
  cout << endl;
  return 0;
}
