func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, t;   char v[500010];   vector<pair<int, int> > inter;   int memo[500010];   int calcula(int ind) {     int res = 0;     int x = ind;     int ini = 0;     int fim = 0;     bool erro = false;     int lh = -1;     inter.clear();     for (int i = 0; i < (n); i++) {       if (v[i] ==  H ) {         x--;         lh = i;       } else if (v[i] ==  S ) {         x++;       }       if (x == -1 && !erro) {         ini = i;         erro = true;       }       if (x == 0 && erro) {         if (i < n && v[i + 1] ==  H ) continue;         inter.push_back(make_pair(ini, i));         erro = false;       }     }     if (x < 0) return false;     if ((int)inter.size() == 0) {       if (lh < t) return true;       return false;     }     int i = 0;     res = inter[0].first;     fim = max(lh, inter[(int)inter.size() - 1].second);     memo[inter.size()] = 0;     int next;     for (int i = (int)inter.size() - 1; i >= 0; i--) {       if (i + 1 < (int)inter.size()) {         next = inter[i + 1].first - 1;       } else {         next = fim;       }       memo[i] = min((inter[i].second - inter[i].first + 1) * 3 - 2 + memo[i + 1] +                         (next - inter[i].second),                     (fim - inter[i].first + 1) * 2 - 1);     }     res += memo[0];     if (res <= t) return true;     return false;   }   int main() {     scanf( %d %d , &n, &t);     for (int i = 0; i < (n); i++) {       scanf(  %c , &v[i]);     }     int inicio = 0;     int fim = n;     int res = -1;     while (1) {       if (inicio > fim) break;       int meio = (inicio + fim) / 2;       if (calcula(meio)) {         res = meio;         fim = meio - 1;       } else {         inicio = meio + 1;       }     }     printf( %d n , res);     return 0;   }   