#include <bits/stdc++.h>
using namespace std;
struct value_index {
  int v;
  int i;
};
bool compare_value_index(const value_index &x, const value_index &y) {
  return x.v < y.v;
}
void max_min_subarray(const vector<int> &a, vector<int> &result) {
  int n = (int)a.size();
  vector<int> l(n, -1);
  vector<int> r(n, -1);
  for (int i = 1; i < n; ++i) {
    if (a[i] > a[i - 1]) {
      l[i] = i - 1;
    } else if (a[i] == a[i - 1]) {
      l[i] = l[i - 1];
    } else {
      int p = l[i - 1];
      while (p != -1 && a[p] >= a[i]) {
        p = l[p];
      }
      l[i] = p;
    }
  }
  for (int i = n - 2; i >= 0; --i) {
    if (a[i] > a[i + 1]) {
      r[i] = i + 1;
    } else if (a[i] == a[i + 1]) {
      r[i] = r[i + 1];
    } else {
      int p = r[i + 1];
      while (p != -1 && a[p] >= a[i]) {
        p = r[p];
      }
      r[i] = p;
    }
  }
  vector<value_index> survivals(n);
  for (int i = 0; i < n; ++i) {
    survivals[i].i = i;
    if (l[i] != -1) {
      if (r[i] != -1) {
        survivals[i].v = r[i] - l[i] - 1;
      } else {
        survivals[i].v = n - l[i] - 1;
      }
    } else {
      if (r[i] != -1) {
        survivals[i].v = r[i];
      } else {
        survivals[i].v = n;
      }
    }
  }
  ::std::sort(survivals.begin(), survivals.end(), compare_value_index);
  int round = 1;
  int j = 0;
  ::std::multiset<int> xx(a.begin(), a.end());
  while (!xx.empty()) {
    result.push_back(*xx.rbegin());
    while (survivals[j].v == round && j < n) {
      ::std::multiset<int>::iterator lb = xx.lower_bound(a[survivals[j].i]);
      xx.erase(lb);
      ++j;
    }
    ++round;
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  vector<int> result;
  max_min_subarray(a, result);
  cout << result[0];
  for (size_t j = 1; j < result.size(); ++j) {
    cout << " " << result[j];
  }
  return 0;
}
