func_code_string: #include <bits/stdc++.h>   using namespace std;   int n;   string s;   long long rights[1000010], lefts[1000010], mins[1000010];   long long suml[1000010], sumr[1000010];   int min(int a, int b) { return a < b ? a : b; }   int main() {     scanf( %d , &n);     cin >> s;     lefts[0] = 0;     rights[n - 1] = 0;     for (int i = 1; i < n; i++) {       if (s[i - 1] ==  U ) lefts[i]++;       lefts[i] += lefts[i - 1];     }     for (int i = n - 2; i >= 0; i--) {       if (s[i + 1] ==  D ) rights[i]++;       rights[i] += rights[i + 1];     }     for (int i = 0; i < n; i++)       mins[i] = min(lefts[i] + (s[i] ==  U  ? 1 : 0),                     rights[i] + (s[i] ==  D  ? 1 : 0));     long long t = 0;     queue<long long> q;     for (int i = 0; i < n; i++) {       t += q.size();       if (q.size() <= mins[i]) {         suml[i] = t;       } else {         while (q.size() > mins[i]) {           t -= i - q.front();           q.pop();         }         suml[i] = t;       }       if (s[i] ==  U ) q.push(i);     }     while (!q.empty()) q.pop();     t = 0;     for (int i = n - 1; i >= 0; i--) {       t += q.size();       if (q.size() <= mins[i]) {         sumr[i] = t;       } else {         while (q.size() > mins[i]) {           t -= q.front() - i;           q.pop();         }         sumr[i] = t;       }       if (s[i] ==  D ) q.push(i);     }     for (long long i = 0; i < n; i++) {       if (rights[i] > lefts[i]) {         cout << sumr[i] * 2 + suml[i] * 2 + i + 1 <<    ;       } else if (rights[i] < lefts[i]) {         cout << sumr[i] * 2 + suml[i] * 2 + n - i <<    ;       } else {         if (s[i] ==  D )           cout << sumr[i] * 2 + suml[i] * 2 + i + 1 <<    ;         else           cout << sumr[i] * 2 + suml[i] * 2 + n - i <<    ;       }     }     cout << endl;     return 0;   }   