#include <bits/stdc++.h>
using namespace std;
int n;
int dp[200001][17];
int a[200001];
int ans[200001];
void init() {
  for (int i = 0; i < n; ++i) {
    dp[i][0] = a[i];
  }
  for (int j = 1; j < 17; ++j) {
    for (int i = 0; i < n; ++i) {
      dp[i][j] = min(dp[i][j - 1], dp[min(i + (1 << (j - 1)), n - 1)][j - 1]);
    }
  }
}
int query(int x, int y) {
  int ans = 1000001000;
  while (x <= y) {
    int i;
    for (i = 0; i < 17; i++) {
      if (y + 1 < x + (1 << i)) break;
    }
    i--;
    ans = min(ans, dp[x][i]);
    x += (1 << i);
  }
  return ans;
}
int readint() {
  int ans = 0;
  char c;
  while ((c = getchar()) && !(c >= '0' && c <= '9'))
    ;
  do {
    ans = ans * 10 + c - '0';
  } while ((c = getchar()) && (c >= '0' && c <= '9'));
  return ans;
}
int main() {
  n = readint();
  for (int i = 0; i < n; ++i) {
    a[i] = readint();
  }
  init();
  for (int i = 0; i < n; ++i) {
    int L = 0, R = i;
    while (L < R) {
      int mid = (L + R - 1) / 2;
      if (query(mid, i) == a[i]) {
        R = mid;
      } else {
        L = mid + 1;
      }
    }
    int l = L, r;
    L = i;
    R = n - 1;
    while (L < R) {
      int mid = (L + R + 1) / 2;
      if (query(i, mid) == a[i]) {
        L = mid;
      } else {
        R = mid - 1;
      }
    }
    r = L;
    ans[r - l + 1] = max(ans[r - l + 1], a[i]);
  }
  int akt = -1;
  stack<int> s;
  for (int i = n; i >= 1; --i) {
    akt = max(ans[i], akt);
    ans[i] = akt;
  }
  for (int i = 1; i <= n; ++i) {
    printf("%d ", ans[i]);
  }
  printf("\n");
  return 0;
}
