#include <bits/stdc++.h>
using namespace std;
template <typename T>
T in() {
  char ch;
  T n = 0;
  bool ng = false;
  while (1) {
    ch = getchar();
    if (ch == '-') {
      ng = true;
      ch = getchar();
      break;
    }
    if (ch >= '0' && ch <= '9') break;
  }
  while (1) {
    n = n * 10 + (ch - '0');
    ch = getchar();
    if (ch < '0' || ch > '9') break;
  }
  return (ng ? -n : n);
}
int n, ar[300007], Lft[300007], Rgt[300007], Ans[300007], Ok[300007];
int main() {
  n = in<int>();
  for (int i = 1; i < n + 1; i++) {
    ar[i] = in<int>();
  }
  for (int i = 1; i <= n; i++) {
    if (ar[i] <= ar[i - 1]) {
      int id = i - 1;
      while (ar[id] >= ar[i]) {
        int tp = id - Lft[id];
        id = tp;
      }
      Lft[i] = i - id;
    } else {
      Lft[i] = 1;
    }
    if (ar[i] == ar[i - 1]) {
      Ok[i] = Ok[i - 1] + 1;
    } else
      Ok[i] = 1;
  }
  memset(Ok, 0, sizeof(Ok));
  for (int i = n; i >= 1; i--) {
    if (ar[i] <= ar[i + 1]) {
      int id = i + 1;
      while (ar[id] >= ar[i]) {
        int tp = id + Rgt[id];
        id = tp;
      }
      Rgt[i] = id - i;
    } else
      Rgt[i] = 1;
    if (ar[i] == ar[i + 1])
      Ok[i] = Ok[i + 1] + 1;
    else
      Ok[i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    int tp = Lft[i] + Rgt[i] - 1;
    Ans[tp] = max(Ans[tp], ar[i]);
  }
  for (int i = n; i >= 1; i--) {
    Ans[i] = max(Ans[i + 1], Ans[i]);
  }
  for (int i = 1; i < n + 1; i++) printf("%d ", Ans[i]);
  printf("\n");
  return 0;
}
