#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 2e5 + 5;
const int MAXM = MAXN;
const int mod = 1e9 + 7;
int a[MAXN];
struct Node {
  int id, l, r;
  bool operator<(const Node &a) const { return id > a.id; }
} p[MAXN];
struct Point {
  int x, id;
  Point(int _x, int _id) {
    x = _x;
    id = _id;
  }
};
stack<Point> st;
void solve(int a[], int n, int v) {
  for (int i = 1; i <= n; i++) {
    while (st.size() && st.top().x > a[i]) {
      Point nx = st.top();
      st.pop();
      if (v)
        p[nx.id].r = i;
      else
        p[nx.id].l = n - i + 2;
    }
    if (v)
      st.push(Point(a[i], i));
    else
      st.push(Point(a[i], n - i + 1));
  }
  while (st.size()) {
    Point nx = st.top();
    st.pop();
    if (v)
      p[nx.id].r = n + 1;
    else
      p[nx.id].l = 1;
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  solve(a, n, 1);
  reverse(a + 1, a + n + 1);
  solve(a, n, 0);
  for (int i = 1; i <= n; i++) p[i].id = a[n - i + 1];
  sort(p + 1, p + n + 1);
  int pos = 0;
  for (int i = 1; i <= n; i++) {
    while (pos < p[i].r - p[i].l) a[++pos] = p[i].id;
    if (pos == n) break;
  }
  for (int i = 1; i <= n; i++) {
    if (i != 1) putchar(' ');
    printf("%d", a[i]);
  }
  puts("");
  return 0;
}
