#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const int MOD = 1000000007;
struct BIT {
  vector<long long> tree;
  int High;
  BIT(int N) {
    tree.resize(N + 7, -1);
    High = N;
  }
  void addsum(long long x, long long v) {
    while (x <= High) {
      tree[x] = max(v, tree[x]);
      x += (x & -x);
    }
  }
  long long getsum(long long x) {
    long long res = -1;
    while (x) {
      res = max(res, tree[x]);
      x -= (x & -x);
    }
    return res;
  }
  long long getind(long long x) {
    long long idx = 0, mask = High;
    while (mask && idx < High) {
      long long t = idx + mask;
      if (x >= tree[t]) {
        idx = t;
        x -= tree[t];
      }
      mask >>= 1;
    }
    return idx;
  }
};
vector<int> arr, compress, ans, L, R;
int num, Len;
int main(int argc, const char **argv) {
  while (scanf("%d", &num) == 1) {
    arr.resize(num);
    L.resize(num);
    R.resize(num);
    ans.resize(num + 1, -1);
    compress.resize(num);
    for (int i = 0; i <= (num - 1); ++i)
      scanf("%d", &arr[i]), compress[i] = arr[i];
    stable_sort(arr.begin(), arr.end());
    arr.resize(distance(arr.begin(), unique(arr.begin(), arr.end())));
    ;
    for (int i = 0; i <= (num - 1); ++i) {
      compress[i] =
          (lower_bound(arr.begin(), arr.end(), compress[i]) - arr.begin());
    }
    Len = ((int)arr.size());
    BIT Fl(num + 1);
    BIT Fr(num + 1);
    for (int i = 0; i <= (num - 1); ++i) {
      L[i] = Fl.getsum(compress[i]);
      Fl.addsum(compress[i] + 1, i);
    }
    for (int i = (num - 1); i >= 0; --i) {
      R[i] = (num - 1) - Fr.getsum(compress[i]);
      Fr.addsum(compress[i] + 1, (num - i - 1));
    }
    for (int i = 0; i <= (num - 1); ++i) {
      ans[R[i] - L[i] - 1] = max(ans[R[i] - L[i] - 1], compress[i]);
    }
    for (int i = (num - 1); i >= 1; --i) {
      ans[i] = max(ans[i], ans[i + 1]);
    }
    for (int i = 1; i <= num; ++i) {
      printf("%d ", arr[ans[i]]);
    }
    printf("\n");
  }
  return 0;
}
