Problem:
Score : 500 points

Problem Statement

A robot is put at the origin in a two-dimensional plane.
Initially, the robot is facing in the positive x-axis direction.

This robot will be given an instruction sequence s.
s consists of the following two kinds of letters, and will be executed in order from front to back.

F : Move in the current direction by distance 1.

T : Turn 90 degrees, either clockwise or counterclockwise.

The objective of the robot is to be at coordinates (x, y) after all the instructions are executed.
Determine whether this objective is achievable.

Constraints

s consists of F and T.

1 \leq |s| \leq 8 000

x and y are integers.

|x|, |y| \leq |s|

Input

Input is given from Standard Input in the following format:

s
x y

Output

If the objective is achievable, print Yes; if it is not, print No.

Sample Input 1

FTFFTFFF
4 2

Sample Output 1

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T.

Sample Input 2

FTFFTFFF
-2 -2

Sample Output 2

Yes

The objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T.

Sample Input 3

FF
1 0

Sample Output 3

No

Sample Input 4

TF
1 0

Sample Output 4

No

Sample Input 5

FFTTFF
0 0

Sample Output 5

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T.

Sample Input 6

TTTT
1 0

Sample Output 6

No

Solution in C++ (GCC 9.2.1) (judge verdict: Runtime Error)

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;

 
const ll INF = 1e12;
const ll N =(3e4+2); // TODO : change value as per problem
const ll MOD = 1e9+7;
bool dp[N][N];
bool dp2[N][N];
ll get(ll x){
	return x + 10000;
}

void solve(){
	string s;
	cin >> s;
	int x,y;
	cin >> x >> y;
	int idx=-1;
	int wow = 0;
	for(int i =0;i < sz(s);i++){
		if(s[i] == 'T') {idx = i;break;}
		wow++;
	}
	vll a,b;
	bool ok = false;
	ll c = 0;
	for(int i = idx+1;i<sz(s);i++){
		// cout << s[i] << " " << ok<< endl;
		if(s[i] == 'T'){
			if(ok) a.pb(c);
			else b.pb(c);
			ok ^= true;
			c = 0;
		}
		else{
			c++;
		}
	}
	if(c != 0){
			if(ok) a.pb(c);
			else b.pb(c);
	}
	ll n = sz(a);
	ll m = sz(b);
	// for(int i =0 ;i<n;i++) cout << a[i] << " ";
	// cout << "\n";
	// for(int i = 0;i<m;i++) cout << b[i] << " ";
	// cout << "\n";
	dp[0][get(wow)] = true;
	// dp[index][sum] 
	int sum = 9000;
	
	for(int i =1;i<=n;i++){
		for(int j = -sum;j<=sum;j++){
			dp[i][get(j)] |= dp[i-1][get(j+a[i-1])];
			 dp[i][get(j)] |= dp[i-1][get(j-a[i-1])];
		}
	}
	dp2[0][get(0)] = true;
	// dp2[1][get(-b[0])] = true;
	// dp2[1][get(b[0])] = true;
	for(int i =1;i<=m;i++){
		for(int j = -sum;j<=sum;j++){
			dp2[i][get(j)] |= dp2[i-1][get(j+b[i-1])];
			dp2[i][get(j)] |= dp2[i-1][get(j-b[i-1])];
		}
	}

	if(dp[n][get(x)] && dp2[n][get(y)])
		cout << "Yes\n";
	else 
		cout << "No\n";
}
signed main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     // freopen(".in","r",stdin);freopen(".out","w",stdout);
    
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}