func_code_string: #include <bits/stdc++.h>   using namespace std;   long n, tim;   string st;   long lpos, calc1, calc2;   long need, ans, calc;   long l, r, has, bad;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> tim;     cin >> st;     lpos = -1;     for (int i = 0; i < st.size(); i++) {       if (st[i] ==  H ) ++calc1;       if (st[i] ==  H ) lpos = i;       if (st[i] ==  S ) ++calc2;     }     if (tim <= lpos) {       cout << -1 << endl;       return 0;     }     l = 0;     r = 1e6;     if (calc1 > calc2) l = calc1 - calc2;     while (l < r) {       long mid = l + r;       mid /= 2;       calc = 0;       has = mid;       bad = 1e9;       need = 0;       long oscore = 1e9;       long tt = mid;       long epos = 0;       for (int i = 0; i < st.size(); i++) {         if (tt < calc1) epos = i;         if (st[i] ==  S ) ++tt;       }       if (epos < lpos) epos = lpos;       for (long i = 0; i < st.size(); i++) {         ++calc;         if (bad < 1e7)           oscore = min(oscore, epos - i + calc + (epos - bad) * (bad < 1e7));         if (st[i] ==  H ) {           if (has == 0) {             bad = min(bad, i);             need++;           } else {             --has;           }         }         if (st[i] ==  S ) {           ++has;           if (has >= need && i >= lpos) {             if (need) calc += i - bad;             break;           }           if (has >= need && need > 0) {             calc += 2 * (i - bad);             bad = 1e9;             has -= need;             need = 0;           }         }         if (i >= lpos && has >= need) {           if (need) calc += i - bad;           break;         }       }       calc = min(calc, oscore);       if (calc > tim)         l = mid + 1;       else         r = mid;     }     cout << l << endl;     cin.get();     cin.get();     return 0;   }   