func_code_string: #include <bits/stdc++.h>   using namespace std;   long long n;   char str[1000010];   long long cntu[1000010];   long long cntd[1000010];   long long sumu[1000010];   long long sumd[1000010];   long long CNTU;   long long CNTD;   int main() {     scanf( %I64d%s , &n, str + 1);     for (long long i = 1; i <= n; i++) {       cntu[i] = cntu[i - 1];       cntd[i] = cntd[i - 1];       sumu[i] = sumu[i - 1];       sumd[i] = sumd[i - 1];       if (str[i] ==  U ) {         CNTU++;         cntu[i]++;         sumu[i] += i;       } else {         CNTD++;         cntd[i]++;         sumd[i] += i;       }     }     for (long long i = 1; i <= n; i++)       if (str[i] ==  U ) {         if (cntu[i - 1] >= CNTD - cntd[i]) {           long long k =               upper_bound(cntu + 1, cntu + n + 1, cntu[i - 1] - CNTD + cntd[i]) -               cntu;           printf( %I64d  ,                  (-(sumu[i - 1] - sumu[k - 1]) + (sumd[n] - sumd[i])) * 2 + n -                      i + 1);         } else {           long long k =               lower_bound(cntd + 1, cntd + n + 1, cntd[i] + cntu[i - 1] + 1) -               cntd;           printf( %I64d  , (-sumu[i - 1] + (sumd[k] - sumd[i]) - i) * 2 + i);         }       } else {         if (cntu[i - 1] <= CNTD - cntd[i]) {           long long k =               lower_bound(cntd + i, cntd + n + 1, cntd[i] + cntu[i - 1]) - cntd;           printf( %I64d  , (-sumu[i - 1] + (sumd[k] - sumd[i])) * 2 + i);         } else {           long long k = upper_bound(cntu + 1, cntu + n + 1,                                     cntu[i - 1] - CNTD + cntd[i] - 1) -                         cntu;           printf( %I64d  ,                  (i - (sumu[i - 1] - sumu[k - 1]) + (sumd[n] - sumd[i])) * 2 + n -                      i + 1);         }       }     return 0;   }   