#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const long long INF = 1e15;
const long long MOD = 1e9 + 7;
const int N = 1000005;
const int M = 600000;
struct Point {
  int x, v;
  Point() {}
  Point(int x, int v) : x(x), v(v) {}
  bool operator<(const Point& a) const { return v > a.v; }
  void read(int o) {
    x = o;
    scanf("%d", &v);
  }
} p[200005];
int n, A[200005];
int Mx[600000], L[200005], R[200005];
int ans[200005];
void Add(int l, int r, int o, int L, int R, int v) {
  if (L <= l && r <= R) {
    Mx[o] = max(Mx[o], v);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) Add(l, mid, o << 1, L, R, v);
  if (mid < R) Add(mid + 1, r, (o << 1) | 1, L, R, v);
}
void Final(int l, int r, int o) {
  if (l == r) {
    ans[l] = Mx[o];
    return;
  }
  int mid = (l + r) >> 1;
  if (Mx[o]) {
    Mx[o << 1] = max(Mx[o], Mx[o << 1]);
    Mx[(o << 1) | 1] = max(Mx[o], Mx[(o << 1) | 1]);
  }
  Final(l, mid, o << 1);
  Final(mid + 1, r, (o << 1) | 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) p[i].read(i), A[i] = p[i].v;
  sort(p, p + n);
  memset(L, -1, sizeof(L));
  memset(R, -1, sizeof(R));
  memset(Mx, 0, sizeof(Mx));
  for (int i = 0; i < n; i++) {
    int l = p[i].x, r = p[i].x;
    if (p[i].x && L[p[i].x - 1] != -1) {
      l = L[p[i].x - 1];
    }
    if (p[i].x < n - 1 && R[p[i].x + 1] != -1) {
      r = R[p[i].x + 1];
    }
    Add(0, n - 1, 1, 0, r - l, p[i].v);
    R[l] = r;
    L[r] = l;
  }
  Final(0, n - 1, 1);
  for (int i = 0; i < n; i++) {
    if (i) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
  return 0;
}
