#include <bits/stdc++.h>
using namespace std;
int xx[4] = {0, 0, 1, -1};
int yy[4] = {1, -1, 0, 0};
int n;
int a[int(2e5 + 100)];
int l[int(2e5 + 100)][20], r[int(2e5 + 100)][20];
pair<int, int> q[int(2e5 + 100)];
int main() {
  scanf("%d", &n);
  for (int i = (1), _b = (n); i <= _b; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = (1), _b = (n); i <= _b; i++) {
    l[i][0] = a[i];
    for (int j = (1), _b = (18); j <= _b; j++)
      if (i - (1 << (j - 1)) >= 0) {
        l[i][j] = min(l[i][j - 1], l[i - (1 << (j - 1))][j - 1]);
      }
  }
  for (int i = (n), _a = (1); i >= _a; i--) {
    r[i][0] = a[i];
    for (int j = (1), _b = (18); j <= _b; j++)
      if (i + (1 << (j - 1)) <= n + 1)
        r[i][j] = min(r[i][j - 1], r[i + (1 << (j - 1))][j - 1]);
  }
  for (int i = (1), _b = (n); i <= _b; i++) {
    int x = i;
    for (int j = (18), _a = (0); j >= _a; j--)
      if (l[x][j] >= a[i]) {
        x -= (1 << j);
      }
    int y = i;
    for (int j = (18), _a = (0); j >= _a; j--)
      if (r[y][j] >= a[i]) {
        y += (1 << j);
      }
    q[i].first = a[i];
    q[i].second = y - x - 1;
  }
  sort(q + 1, q + 1 + n);
  int j = n;
  for (int i = (1), _b = (n); i <= _b; i++) {
    while (j > 1 && q[j].second < i) j--;
    printf("%d ", q[j].first);
  }
}
