func_code_string: #include <bits/stdc++.h>   using namespace std;   long long n, a[500011], L[500011], R[500011], aL[500011], aR[500011],       ans[500011];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long i = 1; i <= n; i++) cin >> a[i];     stack<pair<long long, long long> > st;     for (long long i = 1; i <= n; i++) {       while (!st.empty() && st.top().first >= a[i]) st.pop();       if (st.empty())         L[i] = 0;       else {         L[i] = st.top().second;       }       st.push(pair<long long, long long>(a[i], i));     }     while (!st.empty()) st.pop();     for (long long i = n; i >= 1; i--) {       while (!st.empty() && st.top().first >= a[i]) st.pop();       if (st.empty())         R[i] = n + 1;       else         R[i] = st.top().second;       st.push(pair<long long, long long>(a[i], i));     }     for (long long i = 1; i <= n; i++) {       aL[i] = aL[L[i]] + a[i] * (i - L[i]);     }     for (long long i = n; i >= 1; i--) {       aR[i] = aR[R[i]] + a[i] * (R[i] - i);     }     long long A = 0, pos = 0;     for (long long i = 1; i <= n; i++) {       if (aL[i] + aR[i] - a[i] > A) {         A = aL[i] + aR[i] - a[i];         pos = i;       }     }     ans[pos] = a[pos];     long long cur_min = ans[pos];     for (long long i = pos - 1; i >= 1; i--) {       ans[i] = min(a[i], cur_min);       cur_min = min(a[i], cur_min);     }     cur_min = ans[pos];     for (long long i = pos + 1; i <= n; i++) {       ans[i] = min(a[i], cur_min);       cur_min = min(a[i], cur_min);     }     for (long long i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }   