#include <bits/stdc++.h>
using namespace std;
inline void in(int &n) {
  n = 0;
  int ch = getchar();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
  }
  n = n * sign;
}
int a[200005], myleft[200005], myright[200005];
vector<int> adj[200005];
int main() {
  int n;
  in(n);
  for (int i = 1; i <= n; i++) {
    in(a[i]);
  }
  stack<int> S;
  for (int i = 1; i <= n; i++) {
    while (S.size() > 0 && a[i] <= a[S.top()]) {
      S.pop();
    }
    if (S.size() == 0) {
      myleft[i] = 1;
    } else {
      myleft[i] = S.top() + 1;
    }
    S.push(i);
  }
  while (S.size()) {
    S.pop();
  }
  for (int i = n; i >= 1; i--) {
    while (S.size() > 0 && a[i] <= a[S.top()]) {
      S.pop();
    }
    if (S.size() == 0) {
      myright[i] = n;
    } else {
      myright[i] = S.top() - 1;
    }
    S.push(i);
  }
  vector<pair<int, int> > v;
  for (int i = 1; i <= n; i++) {
    v.push_back(pair<int, int>(a[i], i));
  }
  sort(v.begin(), v.end());
  int cnt = 1;
  adj[cnt].push_back(v[0].second);
  for (int i = 1; i < v.size(); i++) {
    if (v[i].first == v[i - 1].first) {
      adj[cnt].push_back(v[i].second);
    } else {
      cnt++;
      adj[cnt].push_back(v[i].second);
    }
  }
  int ans = 1;
  vector<int> res;
  for (int i = cnt; i >= 1; i--) {
    for (int j = 0; j < adj[i].size(); j++) {
      int l, r;
      l = myleft[adj[i][j]];
      r = myright[adj[i][j]];
      int diff = r - l + 1;
      if (diff < ans) {
        continue;
      }
      while (ans <= diff) {
        ans++;
        res.push_back(a[adj[i][j]]);
      }
    }
  }
  for (int i = 0; i < res.size(); i++) {
    printf("%d ", res[i]);
  }
  printf("\n");
  return 0;
}
