#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int INF = 1e9;   const long long mod = 1e9 + 7;   bool dp[105][55][2][2][205];   string s;   int n, sz, realans;   int offset(int x) { return x + 100; }   bool f(int idx, int sisa, bool flip, bool arah, int ans) {     if (idx == sz + 1) {       if (sisa == 0) {         realans = max(realans, abs(ans));       }       return 1;     }     bool &res = dp[idx][sisa][flip][arah][offset(ans)];     if (res == 1) return res;     char now = s[idx - 1];     if (flip) {       if (now ==  F )         now =  T ;       else         now =  F ;     }     if (now ==  F ) {       res = f(idx + 1, sisa, 0, arah, ans + (arah ? 1 : -1));       if (sisa) res = f(idx, sisa - 1, !flip, arah, ans);     } else if (now ==  T ) {       res = f(idx + 1, sisa, 0, !arah, ans);       if (sisa) res = f(idx, sisa - 1, !flip, arah, ans);     }     return res = 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> s;     cin >> n;     sz = s.size();     f(1, n, 0, 1, 0);     cout << realans << endl;   }   