#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e15;
const long long int mod = 1000000007;
const int infInt = 2e9;
const double PI = acos(-1.00);
const double eps = 1e-6;
int a[200010];
int minaux[200010][22], n;
void pre() {
  int i, j;
  for (i = 1; i <= n; i++) minaux[i][0] = a[i];
  for (j = 1; (1 << j) <= n; j++)
    for (i = 1; i + (1 << j) - 1 <= n; i++) {
      minaux[i][j] = min(minaux[i][j - 1], minaux[i + (1 << (j - 1))][j - 1]);
    }
}
int rmq(int x, int y) {
  int k = log2(y - x + 1);
  return min(minaux[x][k], minaux[y - (1 << k) + 1][k]);
}
int res[200010];
int main() {
  cin.sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  int mini = infInt, maxi = -infInt;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mini = min(mini, a[i]);
    maxi = max(maxi, a[i]);
  }
  pre();
  for (int i = 1; i <= n; i++) {
    int ini = 1, fin = i;
    int ans = 1;
    while (ini <= fin) {
      int mid = (ini + fin) / 2;
      int q = rmq(i - mid + 1, i);
      if (q >= a[i]) {
        ans = max(ans, mid);
        ini = mid + 1;
      } else {
        fin = mid - 1;
      }
    }
    ini = 1;
    fin = n - i + 1;
    int ans2 = 1;
    while (ini <= fin) {
      int mid = (ini + fin) / 2;
      int q = rmq(i, i + mid - 1);
      if (q >= a[i]) {
        ans2 = max(ans2, mid);
        ini = mid + 1;
      } else {
        fin = mid - 1;
      }
    }
    ans += ans2 - 1;
    res[ans] = max(a[i], res[ans]);
  }
  for (int i = n; i >= 1; i--) {
    res[i] = max(res[i], res[i + 1]);
  }
  for (int i = 1; i <= n; i++) cout << res[i] << " ";
  return 0;
}
