func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<int> houses, shops;   int lasthouse = -1, lastshop = -1;   bool check(int k, int t, string s) {     int l = s.length(), min_index = -1, ans = 0, ct = 0;     int ans2 = t + 1;     if (lasthouse > lastshop) {       if (lastshop == -1) {         if (k < houses[lasthouse])           return false;         else {           if (lasthouse > t)             return false;           else {             return true;           }         }       } else {         if (k + shops[lastshop] >= houses[lasthouse]) {           ans2 = lasthouse + lasthouse - 1;         }       }     } else {       for (int i = lasthouse; i <= lastshop; i++) {         if (shops[i] + k >= houses[lasthouse]) {           ans2 = i + i - 1;           break;         }       }     }     for (int i = 0; i < l; i++) {       if (s[i] ==  H ) {         if (k > 0) {           k--;           ct = i + 1;         } else {           if (min_index == -1) min_index = i;         }       } else if (s[i] ==  S ) {         k++;         if (min_index != -1 && k >= houses[i + 1] - houses[min_index]) {           k -= (houses[i + 1] - houses[min_index]);           if (houses[l] - houses[i])             ans += 2 * (i - min_index);           else             ans += (i - min_index);           min_index = -1;           ct = i + 1;         }       }     }     ans += ct;     if ((min(ans, ans2) > t || min_index != -1)) return false;     return true;   }   int bin_search(int start, int end, string s, int t) {     if (start == end)       if (check(start, t, s))         return start;       else         return -1;     if (start > end) return -1;     int mid = (start + end) / 2;     if (check(mid, t, s)) {       return bin_search(start, mid, s, t);     } else {       return bin_search(mid + 1, end, s, t);     }   }   int main() {     int n, t;     cin >> n >> t;     string s;     cin >> s;     int l = s.length();     houses = vector<int>(l + 1, 0);     shops = vector<int>(l + 1, 0);     for (int i = 1; i <= l; i++) {       if (s[i - 1] ==  H ) {         houses[i] = 1;         lasthouse = i;       }       if (s[i - 1] ==  S ) {         shops[i] = 1;         lastshop = i;       }     }     for (int i = 1; i <= l; i++) {       houses[i] += houses[i - 1];       shops[i] += shops[i - 1];     }     cout << bin_search(0, l, s, t) <<    ;   }   