#include <bits/stdc++.h>
using namespace std;
string s;
vector<int> solve(vector<int> &arr, int lo, int hi) {
  if (lo > hi) return vector<int>();
  if (lo == hi) {
    vector<int> ans;
    ans.push_back(arr[lo]);
    return ans;
  }
  int mid = (lo + hi) / 2;
  vector<int> left = solve(arr, lo, mid);
  vector<int> right = solve(arr, mid + 1, hi);
  vector<int> midL, midR;
  for (int i = mid; i >= lo; i--) {
    midL.push_back(min(arr[i], i == mid ? 0 : midL.back()));
  }
  for (int i = mid + 1; i <= hi; i++) {
    midR.push_back(min(arr[i], i == mid + 1 ? 0 : midR.back()));
  }
  vector<int> ans;
  int p1 = mid;
  int p2 = mid + 1;
  ans.push_back(0);
  int MIN = min(arr[p1], arr[p2]);
  ans.push_back(MIN);
  while (p1 != lo || p2 != hi) {
    if (p1 == lo)
      p2++;
    else if (p2 == hi)
      p1--;
    else if (arr[p1 - 1] < arr[p2 + 1])
      p2++;
    else
      p1--;
    MIN = min(min(MIN, arr[p1]), arr[p2]);
    ans.push_back(MIN);
  }
  for (int i = int(0); i < int(ans.size()); i++)
    ans[i] = max(ans[i], max(left.size() > i ? left[i] : 0,
                             right.size() > i ? right[i] : 0));
  return ans;
}
int main() {
  int N;
  cin >> N;
  vector<int> arr(N, 0);
  for (int i = int(0); i < int(N); i++) cin >> arr[i];
  vector<int> ans = solve(arr, 0, arr.size() - 1);
  for (int i = int(0); i < int(ans.size()); i++) cout << ans[i] << " ";
  cout << endl;
}
