#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
struct node {
  int val, id;
  bool operator<(const node &A) const {
    return val == A.val ? id < A.id : val > A.val;
  }
};
set<node> S;
int vis[maxn];
int fa[maxn], siz[maxn];
int ans[maxn];
int find(int x) {
  if (x != fa[x]) fa[x] = find(fa[x]);
  return fa[x];
}
int unio(int a, int b) {
  int va = find(a);
  int vb = find(b);
  if (va != vb) {
    if (va < vb) {
      fa[vb] = va;
      siz[va] += siz[vb];
      siz[vb] = 0;
      return siz[va];
    } else {
      fa[va] = vb;
      siz[vb] += siz[va];
      siz[va] = 0;
      return siz[vb];
    }
  }
  return max(siz[va], siz[vb]);
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    node a;
    a.id = i;
    a.val = x;
    S.insert(a);
  }
  set<node>::iterator it;
  memset(vis, 0, sizeof(vis));
  memset(ans, 0, sizeof(ans));
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    siz[i] = 1;
  }
  int len = 0;
  for (it = S.begin(); it != S.end(); it++) {
    int x = (*it).id;
    vis[x] = 1;
    int L = 1, R = 0, pre = x;
    for (int i = x - 1; i >= 1; i--) {
      if (find(i) == find(pre)) break;
      if (vis[i])
        L = unio(i, i + 1), pre = i;
      else
        break;
    }
    for (int i = x + 1; i <= n; i++) {
      if (find(i) == find(pre)) break;
      if (vis[i])
        R = unio(pre, i);
      else
        break;
    }
    L = max(L, R);
    if (L > len) {
      for (int j = len + 1; j <= L; j++) {
        ans[j] = (*it).val;
      }
      len = L;
    }
  }
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  puts("");
}
