#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int n, a;
vector<int> input;
int l[200000];
int r[200000];
int ans[200000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < (int)n; i++) {
    cin >> a;
    input.push_back(a);
    l[i] = r[i] = i;
  }
  for (int i = 1; i < (int)n; i++) {
    while (l[i] > 0 && input[i] <= input[l[i] - 1]) l[i] = l[l[i] - 1];
  }
  for (int i = n - 2; i >= 0; i--) {
    while (r[i] < n - 1 && input[i] <= input[r[i] + 1]) r[i] = r[r[i] + 1];
  }
  for (int i = 0; i < (int)n; i++) {
    int len = r[i] - l[i] + 1;
    ans[len - 1] = max(ans[len - 1], input[i]);
  }
  for (int i = 0; i < (int)n - 1; i++) {
    if (ans[i] == 0 || ans[i] < ans[i + 1]) {
      for (int j = i + 1; j < (int)n; j++) {
        if (ans[j] > ans[i]) {
          for (int k = j - 1; k >= 0; k--) {
            if (ans[k] < ans[j])
              ans[k] = ans[j];
            else
              break;
          }
          break;
        }
      }
    }
  }
  for (int i = 0; i < (int)n; i++) cout << ans[i] << " ";
  cout << endl;
}
