func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 510000;   char s[maxn];   int n, maxtime;   int house;   bool ok(int need) {     int time = 0, candy = need, total = house;     int p = 0, q = 0;     int i;     for (i = 0; i < n; i++) {       p += (s[i] ==  H );       q += (s[i] ==  S );       if (p == total && (q + need) >= house) break;     }     if (!(p == total && (q + need) >= house)) return 0;     if (2 * (i + 1) - 1 <= maxtime) return 1;     for (int i = 0; i < n; i++) {       if (!total) return time <= maxtime;       if (++time > maxtime) return 0;       if (s[i] ==  S ) {         candy++;       } else if (s[i] ==  H ) {         if (candy) {           candy--;           total--;           continue;         }         int h2 = 0, k = 0, j;         for (j = i; j < n; j++) {           if (s[j] ==  H )             k++, h2++;           else if (s[j] ==  S )             k--, s[j] =  . ;           if (k == 0) break;         }         if (k) return 0;         time += 2 * (j - i);         time--;         candy += h2;         i--;       }     }     return time <= maxtime;   }   char str[maxn];   int main() {     while (scanf( %d%d , &n, &maxtime) != EOF) {       scanf( %s , str);       house = 0;       for (int i = 0; i < n; i++) {         house += (str[i] ==  H );       }       int l = 0, r = n;       int ans = -1;       while (l <= r) {         int m = (l + r) >> 1;         memcpy(s, str, sizeof s);         if (ok(m)) {           r = m - 1;           ans = m;         } else           l = m + 1;       }       printf( %d n , ans);     }     return 0;   }   