func_code_string: #include <bits/stdc++.h>   using namespace std;   const int64_t M = 1000000007;   const int64_t MM = 998244353;   template <typename T, typename U>   static inline void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static inline void amax(T &x, U y) {     if (x < y) x = y;   }   int64_t _runtimeTerror_() {     int64_t n;     cin >> n;     string s;     cin >> s;     vector<long long> d_cnt(n + 1, 0), d_sum(n + 1), u_cnt(n + 1),         u_sum(n + 1, 0);     for (int64_t i = 1; i <= n; ++i) {       u_cnt[i] = u_cnt[i - 1];       u_sum[i] = u_sum[i - 1];       d_cnt[i] = d_cnt[i - 1];       d_sum[i] = d_sum[i - 1];       if (s[i - 1] ==  D ) {         d_cnt[i] += 1;         d_sum[i] += i;       } else {         u_cnt[i] += 1;         u_sum[i] += i;       }     }     for (int64_t i = 1; i <= n; ++i) {       int64_t ans = 0;       if (s[i - 1] ==  U ) {         int64_t r_d = d_cnt[n] - d_cnt[i];         int64_t l_u = u_cnt[i - 1];         if (r_d > l_u) {           auto it = lower_bound(d_cnt.begin(), d_cnt.end(), d_cnt[i] + l_u + 1) -                     d_cnt.begin();           ans += (d_sum[it] - d_sum[i] - (i * (l_u + 1))) * 2;           ans -= (u_sum[i - 1]) * 2;           ans += l_u * i * 2;           ans += i;         } else {           ans += (d_sum[n] - d_sum[i] - (d_cnt[n] - d_cnt[i]) * i) * 2;           ans += (n - i + 1);           auto it =               lower_bound(u_cnt.begin(), u_cnt.end(), u_cnt[i - 1] - r_d + 1) -               u_cnt.begin();           ans -= (u_sum[i - 1] - u_sum[it - 1]) * 2;           ans += (r_d * i) * 2;         }         cout << ans <<    ;       } else {         int64_t r_d = d_cnt[n] - d_cnt[i];         int64_t l_u = u_cnt[i - 1];         if (r_d >= l_u) {           auto it = lower_bound(d_cnt.begin(), d_cnt.end(), d_cnt[i] + l_u) -                     d_cnt.begin();           ans += (d_sum[it] - d_sum[i] - (i * (l_u))) * 2;           ans -= (u_sum[i - 1]) * 2;           ans += l_u * i * 2;           ans += i;         } else {           ans += (d_sum[n] - d_sum[i] - (d_cnt[n] - d_cnt[i]) * i) * 2;           ans += (n - i + 1);           auto it = lower_bound(u_cnt.begin(), u_cnt.end(), u_cnt[i - 1] - r_d) -                     u_cnt.begin();           ans -= (u_sum[i - 1] - u_sum[it - 1]) * 2;           ans += ((r_d + 1) * i) * 2;         }         cout << ans <<    ;       }     }     return 0;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int64_t TESTS = 1;     while (TESTS--) _runtimeTerror_();     return 0;   }   