#include <bits/stdc++.h>   using namespace std;   int f[201000], l[201000], r[201000];   int n;   int a[201000], s[201000];   int top;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     top = 0;     s[top] = 0;     a[0] = 0;     for (int i = 1; i <= n; i++) {       while (a[s[top]] >= a[i]) top--;       l[i] = s[top] + 1;       top++;       s[top] = i;     }     top = 0;     s[top] = n + 1;     a[n + 1] = 0;     for (int i = n; i >= 1; i--) {       while (a[s[top]] >= a[i]) top--;       r[i] = s[top] - 1;       top++;       s[top] = i;     }     for (int i = 1; i <= n; i++)       f[r[i] - l[i] + 1] = max(f[r[i] - l[i] + 1], a[i]);     for (int i = n; i >= 1; i--) f[i] = max(f[i], f[i + 1]);     for (int i = 1; i <= n; i++) cout << f[i] <<    ;     return 0;   }   