#include <bits/stdc++.h>
using namespace std;
int stk[200005], len[200005], ans[200005];
int main() {
  int n;
  cin >> n;
  int tail = 1;
  scanf("%d", &stk[1]);
  len[1] = 1;
  for (int i = 2; i <= n; i++) {
    int h;
    scanf("%d", &h);
    int pre = i;
    if (ans[1] < h) ans[1] = h;
    int l = 0;
    while (stk[tail] >= h) {
      l += len[tail];
      if (ans[l + 1] < h) ans[l + 1] = h;
      if (ans[l] < stk[tail]) ans[l] = stk[tail];
      tail--;
    }
    stk[++tail] = h;
    len[tail] = l + 1;
  }
  int l = 0;
  for (int i = tail; i > 0; i--) {
    l += len[i];
    if (ans[l] < stk[i]) ans[l] = stk[i];
  }
  for (int i = n; i >= 2; i--)
    if (ans[i - 1] < ans[i]) ans[i - 1] = ans[i];
  printf("%d", ans[1]);
  for (int i = 2; i <= n; i++) printf(" %d", ans[i]);
}
