func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class T>   int getbit(T s, int i) {     return (s >> i) & 1;   }   template <class T>   T onbit(T s, int i) {     return s | (T(1) << i);   }   template <class T>   T offbit(T s, int i) {     return s & (~(T(1) << i));   }   template <class T>   int cntbit(T s) {     return __builtin_popcount(s);   }   template <class T>   T gcd(T a, T b) {     T r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   int n;   string s;   long long u[2000005], d[2000005];   long long nu[2000005], nd[2000005];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> s;     memset(nu, 0, sizeof(nu));     memset(nd, 0, sizeof(nd));     memset(u, 0, sizeof(u));     memset(d, 0, sizeof(d));     for (int i = (1); i <= (n); ++i) {       char ch = s[i - 1];       nu[i] = nu[i - 1];       nd[i] = nd[i - 1];       if (ch ==  U ) {         nu[i]++;         u[nu[i]] = u[nu[i] - 1] + i;       } else {         nd[i]++;         d[nd[i]] = d[nd[i] - 1] + i;       }     }     for (int i = (1); i <= (n); ++i) {       char ch = s[i - 1];       long long res = 0;       if (ch ==  U ) {         long long numd = nd[n] - nd[i];         long long numu = nu[i];         if (numd < numu) {           res += (d[nd[i] + numd] - d[nd[i]]) * 2 + n + 1;           res -= (u[nu[i]] - u[nu[i] - numd - 1]) * 2 - i;         } else {           res += (d[nd[i] + numu] - d[nd[i]]) * 2;           res -= (u[nu[i]]) * 2 - i;         }       } else {         long long numd = nd[n] - nd[i - 1];         long long numu = nu[i];         if (numd <= numu) {           res += (d[nd[i - 1] + numd] - d[nd[i - 1]]) * 2 + n + 1 - i;           res -= (u[nu[i]] - u[nu[i] - numd]) * 2;         } else {           res += (d[nd[i] + numu] - d[nd[i - 1]]) * 2 - i;           res -= (u[nu[i]]) * 2;         }       }       cout << res <<    ;     }     return 0;   }   