func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, t;   char G[500005];   int solve(int k) {     int last = n, i;     int hs, ss;     hs = ss = 0;     for (i = 1; i <= n; i++) {       if (G[i] ==  H ) hs++;       if (G[i] ==  S ) ss++;       if (G[i] ==  H ) last = i;       if (hs - ss >= k && G[i] !=  . ) last = i;     }     if (hs - ss > k) {       return 0;     }     if (t < last) return 0;     int remT = t - 1;     int pos, val = k, twice, st;     for (pos = 1; pos <= last; pos++) {       if (remT < 0) return 0;       if (G[pos] ==  H ) {         if (val > 0)           val--;         else {           twice = (last - pos) << 1;           if (twice <= remT) {             return 1;           } else {             st = pos;             ss = hs = 0;             for (; pos <= last; pos++) {               if (G[pos] ==  H )                 hs++;               else if (G[pos] ==  S )                 ss++;               if (hs <= ss) break;             }             if (pos > last) {               return 0;             }             twice = (pos - st) * 3;             remT -= twice;             if (remT < 0) return 0;           }         }       } else if (G[pos] ==  S )         val++;       remT--;     }     return 1;   }   int main() {     scanf( %d%d , &n, &t);     scanf( %s , G + 1);     int high = n + 1;     int low = 0;     int mid;     while (low < high) {       mid = (low + high) / 2;       if (solve(mid)) {         high = mid;       } else {         low = mid + 1;       }     }     if (high <= n)       printf( %d , high);     else       printf( -1 );     return 0;   }   