#include <bits/stdc++.h>
using namespace std;
int arr[200015];
pair<int, int> Stack[200015];
int N;
int cur = 0;
int Left[200015];
int Right[200015];
pair<int, int> Ran[200015];
bool first = false;
inline void input() {
  for (int i = 1; i <= N; i++) cin >> arr[i];
}
inline void build() {
  cur = 0;
  Stack[cur++] = make_pair(arr[1], 1);
  Left[1] = 0;
  for (int i = 2; i <= N; i++) {
    Left[i] = 0;
    while (cur > 0 && Stack[cur - 1].first >= arr[i]) {
      cur--;
      Left[i] = i - Stack[cur].second + Left[Stack[cur].second];
    }
    Stack[cur++] = make_pair(arr[i], i);
  }
  cur = 0;
  Stack[cur++] = make_pair(arr[N], N);
  Right[N] = 0;
  for (int i = N - 1; i >= 1; i--) {
    Right[i] = 0;
    while (cur > 0 && Stack[cur - 1].first >= arr[i]) {
      cur--;
      Right[i] = Stack[cur].second - i + Right[Stack[cur].second];
    }
    Stack[cur++] = make_pair(arr[i], i);
  }
  for (int i = 1; i <= N; i++) {
    Ran[i].first = arr[i];
    Ran[i].second = 1 + Left[i] + Right[i];
  }
  sort(Ran + 1, Ran + 1 + N, greater<pair<int, int> >());
}
inline void solve() {
  cur = 1;
  first = false;
  for (int r = 1; r <= N; r++) {
    while (Ran[cur].second < r) cur++;
    if (first) cout << " ";
    cout << Ran[cur].first;
    first = true;
  }
}
int main() {
  while (cin >> N) {
    input();
    build();
    solve();
  }
  return 0;
}
