func_code_string: #include <bits/stdc++.h>   using namespace std;   char s[1000100];   int n;   int d[1000100];   int dp(int x) {     if (d[x] != -1) return d[x];     int ret = 0;     int ind = x + 1;     while (s[ind] ==  M ) {       ret += 1;       ind++;     }     int w = 0;     while (s[ind] ==  F  && ind < n) ind++, w++;     if (ind == n)       return d[x] = ret;     else {       int rety = dp(ind);       if (w > rety)         return d[x] = ret;       else         return d[x] = dp(ind) + 1 - w + ret;     }   }   int main() {     while (scanf( %s , s) != EOF) {       n = strlen(s);       memset(d, -1, sizeof(d));       int cntm = 0;       for (int i = 0; i < n; i++)         if (s[i] ==  M ) cntm++;       for (int i = n - 1; i >= 0; i--) {         if (s[i] ==  M )           d[i] = 0;         else           break;       }       int st = -1;       for (int i = 0; i < n; i++)         if (s[i] ==  M ) {           st = i;           break;         }       if (st == -1) {         puts( 0 );         continue;       }       dp(st);       printf( %d n , d[st] + (n - 1 - cntm + 1) - st);     }     return 0;   }   