#include <bits/stdc++.h>
using namespace std;
const int md = 1000000007;
const int maxn = 201010;
const int maxn4 = 4 * maxn;
const long long inf = 2020202020202020202LL;
int n, a[maxn], mn[maxn], pl[maxn], pr[maxn];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<pair<int, int>> lolst;
  for (int i = 0; i < n; i++) {
    while (1) {
      if (lolst.size()) {
        if (lolst[lolst.size() - 1].first > a[i])
          lolst.pop_back();
        else
          break;
      } else
        break;
    }
    if (lolst.size())
      pl[i] = i - lolst[lolst.size() - 1].second;
    else
      pl[i] = i + 1;
    lolst.push_back(make_pair(a[i], i));
  }
  lolst.resize(0);
  for (int i = n - 1; i >= 0; i--) {
    while (1) {
      if (lolst.size()) {
        if (lolst[lolst.size() - 1].first >= a[i])
          lolst.pop_back();
        else
          break;
      } else
        break;
    }
    if (lolst.size())
      pr[i] = lolst[lolst.size() - 1].second - i;
    else
      pr[i] = n - i;
    lolst.push_back(make_pair(a[i], i));
  }
  for (int i = 0; i < n; i++)
    mn[pl[i] + pr[i] - 1] = max(mn[pl[i] + pr[i] - 1], a[i]);
  for (int i = 0; i < n - 1; i++) mn[n - i - 1] = max(mn[n - i - 1], mn[n - i]);
  for (int i = 0; i < n; i++) cout << mn[i + 1] << " ";
  return 0;
}
