func_code_string: #include <bits/stdc++.h>   using namespace std;   long long n, cntu[1000006], cntd[1000006], preu[1000006], pred[1000006];   string s;   vector<long long> lisu, lisd;   int main() {     ios::sync_with_stdio(0);     cin >> n >> s;     lisd.push_back(0);     lisu.push_back(0);     for (int i = 1; i <= n; i++) {       if (s[i - 1] ==  D )         cntd[i]++;       else         cntu[i]++;       cntd[i] += cntd[i - 1];       cntu[i] += cntu[i - 1];       if (s[i - 1] ==  D )         pred[i] += i;       else         preu[i] += i;       pred[i] += pred[i - 1];       preu[i] += preu[i - 1];       if (s[i - 1] ==  D ) {         lisd.push_back(lisd.back() + i);       } else {         lisu.push_back(lisu.back() + i);       }     }     for (int i = 1; i <= n; i++) {       if (s[i - 1] ==  U ) {         long long down_after = cntd[n] - cntd[i];         long long up_before = cntu[i - 1];         if (down_after <= up_before)           cout << 2 * (pred[n] - pred[i]) +                       2 * (-lisu[cntu[i - 1]] + lisu[cntu[i - 1] - down_after]) +                       n - i + 1                <<    ;         else           cout << 2 * (lisd[cntd[i] + up_before + 1] - i - lisd[cntd[i]] -                        lisu[cntu[i - 1]] + lisu[cntu[i - 1] - up_before]) +                       i                <<    ;       } else {         long long down_after = cntd[n] - cntd[i];         long long up_before = cntu[i - 1];         if (up_before <= down_after)           cout << 2 * (lisd[cntd[i] + up_before] - lisd[cntd[i]] -                        lisu[cntu[i - 1]] + lisu[cntu[i - 1] - up_before]) +                       i                <<    ;         else           cout << 2 * (lisd[cntd[i] + down_after] - lisd[cntd[i]] -                        lisu[cntu[i - 1]] + lisu[cntu[i - 1] - down_after - 1] +                        i) +                       n - i + 1                <<    ;       }     }   }   