#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long no_of_input;     long long input;     cin >> no_of_input;     vector<long long> vect1;     for (long long i = 0; i < no_of_input; i++) {       cin >> input;       vect1.push_back(input);     }     stack<long long> stack1;     vector<long long> l(no_of_input + 1, -1);     vector<long long> r(no_of_input + 1, no_of_input);     vector<long long> ans(no_of_input + 1,                           *min_element(vect1.begin(), vect1.end()));     for (long long i = 0; i < no_of_input; i++) {       while (stack1.size() != 0 && vect1[stack1.top()] >= vect1[i]) {         stack1.pop();       }       if (stack1.size() != 0) {         l[i] = stack1.top();       }       stack1.push(i);     }     while (stack1.size() != 0) {       stack1.pop();     }     for (long long i = vect1.size() - 1; i >= 0; i--) {       while (stack1.size() != 0 && vect1[stack1.top()] >= vect1[i]) {         stack1.pop();       }       if (stack1.size() != 0) {         r[i] = stack1.top();       }       stack1.push(i);     }     for (long long i = 0; i < vect1.size(); i++) {       long long idk = r[i] - l[i] - 1;       ans[idk] = max(ans[idk], vect1[i]);     }     long long temp = ans[ans.size() - 1];     for (long long i = ans.size() - 1; i >= 1; i--) {       temp = max(temp, ans[i]);       ans[i] = max(ans[i], temp);     }     for (long long i = 1; i <= no_of_input; i++) {       cout << ans[i] <<    ;     }   }   