func_code_string: #include <bits/stdc++.h>   using namespace std;   long long t[500005], mid;   long long l[500005], r[500005], h[500005];   struct st {     long long h, cnt;   };   stack<st> q;   int main() {     cin.sync_with_stdio(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> t[i];     q.push({-1, 1});     for (int i = 1; i <= n; i++) {       long long c = 0, h = 0;       while (q.top().h >= t[i]) {         c += q.top().cnt;         h += q.top().cnt * q.top().h;         q.pop();       }       l[i] = l[i - 1] - h + (t[i] * (c + 1));       q.push({t[i], c + 1});     }     while (q.size()) q.pop();     q.push({0, 1});     for (int i = n; i > 0; i--) {       long long c = 0, h = 0;       while (q.top().h >= t[i]) {         c += q.top().cnt;         h += q.top().cnt * q.top().h;         q.pop();       }       r[i] = r[i + 1] - h + (t[i] * (c + 1));       q.push({t[i], c + 1});     }     while (q.size()) q.pop();     long long ms = 0;     for (int i = 1; i <= n; i++)       if (l[i] + r[i] - t[i] > ms) ms = l[i] + r[i] - t[i], mid = i;     h[mid] = t[mid];     for (int i = mid + 1; i <= n; i++) {       h[i] = min(h[i - 1], t[i]);     }     for (int i = mid - 1; i > 0; i--) {       h[i] = min(h[i + 1], t[i]);     }     for (int i = 1; i <= n; i++) cout << h[i] <<    ;   }   