#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 20);
int lson[N], rson[N], a[N];
int h[N / 2], len, n;
bool was;
int rmq(int v, int x, int y, int l, int r) {
  if (y < l || r < x) return 1000000001;
  if (l <= x && y <= r) return a[v];
  int mid = (x + y) >> 1;
  int L = (v << 1);
  return min(rmq(L, x, mid, l, r), rmq(L + 1, mid + 1, y, l, r));
}
int S[200010][20];
int sparse(int x, int y) {
  int cur = 18;
  int ans = 1000000001;
  y = min(n, y);
  while (x < y) {
    while ((1 << cur) > (y - x + 1)) --cur;
    ans = min(ans, S[x][cur]);
    x = x + (1 << cur);
  }
  if (x == y) ans = min(ans, S[x][0]);
  return ans;
}
int left_pos(int v, int x, int y, int pos) {
  if (x == y) return x;
  int mid = (x + y) >> 1;
  int L = (v << 1);
  if (lson[L + 1] <= pos && a[L + 1] < h[pos]) {
    int cur = sparse(lson[L + 1], pos);
    if (cur < h[pos]) return left_pos(L + 1, mid + 1, y, pos);
  }
  return left_pos(L, x, mid, pos);
}
int right_pos(int v, int x, int y, int pos) {
  if (x == y) return x;
  int mid = (x + y) >> 1;
  int L = (v << 1);
  if (rson[L] >= pos && a[L] < h[pos]) {
    int cur = sparse(pos, rson[L]);
    if (cur < h[pos]) return right_pos(L, x, mid, pos);
  }
  return right_pos(L + 1, mid + 1, y, pos);
}
int aa[N];
int bb[N];
int maxn;
int rev[N];
int dMax[N];
map<int, int> QQ;
int can[N];
int main() {
  srand(time(0));
  while (1) {
    scanf("%d", &n);
    for (len = 1; len < n; len <<= 1)
      ;
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &aa[i]);
      bb[i] = aa[i];
    }
    sort(bb + 1, bb + n + 1);
    bb[n + 1] = -1;
    for (int i = 1; i <= n; ++i) {
      if (bb[i] == bb[i + 1]) continue;
      ++maxn;
      QQ[bb[i]] = maxn;
      rev[maxn] = bb[i];
    }
    for (int i = 1; i <= n; ++i) {
      h[i] = QQ[aa[i]];
    }
    cerr << "ok\n";
    for (int i = 1; i <= n; ++i) S[i][0] = h[i];
    for (int j = 1; j <= 18; ++j) {
      for (int i = 1; i <= n; ++i) {
        if (i + (1 << j) - 1 > n)
          S[i][j] = 1000000001;
        else if (i + (1 << (j - 1)) <= n)
          S[i][j] = min(S[i][j - 1], S[i + (1 << (j - 1))][j - 1]);
        else
          S[i][j] = S[i][j - 1];
      }
    }
    for (int i = len; i < len + n; ++i) a[i] = h[i - len + 1];
    for (int i = len + n; i < len * 2; ++i) a[i] = 1000000001;
    for (int i = len; i < len * 2; ++i)
      lson[i] = i - len + 1, rson[i] = i - len + 1;
    for (int i = len - 1; i >= 1; --i) {
      int L = (i << 1);
      a[i] = min(a[L], a[L + 1]);
      lson[i] = lson[L];
      rson[i] = rson[L + 1];
    }
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
      was = 0;
      int lp = left_pos(1, 1, len, i);
      if (h[lp] < h[i]) ++lp;
      int rp = right_pos(1, 1, len, i);
      if (h[rp] < h[i]) rp--;
      rp = min(rp, n);
      dMax[h[i]] = max(dMax[h[i]], rp - lp + 1);
    }
    for (int i = maxn; i >= 1; --i) {
      can[i] = max(dMax[i], can[i + 1]);
    }
    for (int i = 1; i <= n; ++i) {
      int l = 1, r = maxn;
      while (l < r) {
        int mid = (l + r + 1) >> 1;
        if (can[mid] < i)
          r = mid - 1;
        else
          l = mid;
      }
      cout << rev[r] << " ";
    }
    return 0;
  }
  return 0;
}
