#include <bits/stdc++.h>
using namespace std;
vector<int> a;
vector<vector<int>> dp;
void build() {
  dp.assign(log2(a.size()) + 1, vector<int>(a.size()));
  dp[0] = a;
  for (int i = 1; i < dp.size(); i++) {
    for (int j = 0; j < a.size(); j++) {
      if (j + (1 << i) - 1 >= a.size()) break;
      dp[i][j] = min(dp[i - 1][j], dp[i - 1][j + (1 << (i - 1))]);
    }
  }
}
int sparse(int l, int r) {
  int d = log2(r - l + 1);
  return min(dp[d][l], dp[d][r - (1 << d) + 1]);
}
void calc(vector<int> &pf, vector<int> &a) {
  int n = a.size();
  pf.resize(n);
  for (int i = 0; i < n; i++) {
    int l = 1, r = i + 1, ans;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (sparse(i - mid + 1, i) >= a[i]) {
        l = mid + 1;
        ans = mid;
      } else
        r = mid - 1;
    }
    pf[i] = ans;
  }
}
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  a.resize(n);
  unordered_map<int, int> ctr;
  for (auto &i : a) {
    cin >> i;
  }
  vector<int> pf, pft;
  build();
  calc(pf, a);
  reverse((a).begin(), (a).end());
  build();
  calc(pft, a);
  reverse((pft).begin(), (pft).end());
  reverse((a).begin(), (a).end());
  for (int i = 0; i < n; i++) {
    int now = a[i], d = pf[i] + pft[i] - 1;
    ctr[now] = max(ctr[now], d);
  }
  vector<pair<int, int>> order;
  unordered_map<int, int> pos;
  for (auto &i : ctr) order.push_back({i.second, i.first});
  sort((order).begin(), (order).end());
  for (int i = 0; i < order.size(); i++) pos[order[i].second] = i;
  int s = 0;
  vector<int> sufmax(order.size());
  for (int i = order.size() - 1; i >= 0; i--) {
    s = max(s, order[i].second);
    sufmax[i] = s;
  }
  for (int i = 1; i <= n; i++) {
    auto it = lower_bound((order).begin(), (order).end(), make_pair(i, i), cmp);
    int l = pos[it->second];
    cout << sufmax[l] << " ";
  }
  return 0;
}
