func_code_string: #include <bits/stdc++.h>   using namespace std;   const int INF = 2000 * 1000 * 1000;   int calc(int sweet, string str) {     int mx = -1;     for (register int i = (0); i < (int)(((int)(str).size())); ++i)       if (sweet > 0 && str[i] ==  H ) {         mx = max(mx, i);         str[i] =  . ;         sweet--;       }     int pos = 0;     vector<pair<int, int> > v;     for (register int i = (0); i < (int)(((int)(str).size())); ++i)       if (str[i] ==  H ) {         while (pos < ((int)(str).size()) && str[pos] !=  S ) pos++;         if (pos == ((int)(str).size())) return INF;         str[pos] =  . ;         if (pos > i)           v.push_back(pair<int, int>(i, pos));         else           mx = max(mx, i);       }     sort((v).begin(), (v).end());     vector<pair<int, int> > u;     for (register int i = (0); i < (int)(((int)(v).size())); ++i)       if (u.empty() || u.back().second < v[i].first)         u.push_back(v[i]);       else         u.back().second = v[i].second;     if (u.empty()) return mx + 1;     mx = max(mx, u.back().second);     int res = mx + 1;     for (__typeof((u).begin()) it = (u).begin(); it != (u).end(); ++it)       res += 2 * (it->second - it->first);     int ans = res;     for (int i = ((int)(u).size()) - 1; i >= 0; i--) {       res -= u[i].second - u[i].first;       res += i + 1 == ((int)(u).size()) ? mx - u.back().second                                         : u[i + 1].first - u[i].second;       ans = min(ans, res);     }     return ans;   }   int main() {     int n, t;     string s;     cin >> n >> t >> s;     if (calc(n, s) > t) {       cout << -1 << endl;       return 0;     }     int mn = 0, mx = n;     while (mn < mx) {       int mid = (mn + mx) / 2;       if (calc(mid, s) <= t)         mx = mid;       else         mn = mid + 1;     }     cout << mn << endl;     return 0;   }   