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++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

string s;
int x,y;

string ans = "No";

void solve(){
	//Fが各どれくらい連続しているかをmove_distに格納
	//例えばFTFFTFFFなら move_dist={1,2,3}とする
	vector<int> move_dist;
	int numof_F = 0;//連続で何回Fが出たか
	for(int i=0;i<s.size();i++){
		if(s[i]=='F'){
			numof_F++;
		}else{
			move_dist.push_back(numof_F);
			numof_F = 0;
			continue;
		}
		if(i==s.size()-1) move_dist.push_back(numof_F);
	}

	vector<int> vertical;//縦方向への動き
	vector<int> horizontal;//横方向への動き
	//デフォルトではx軸正の方向を向いているため
	//move_dist[0]は必ずx軸正の方向に進む
	x -= move_dist[0];
	for(int i=1;i<move_dist.size();i++){
		//縦方向への動き
		if(i%2==1){
			if(move_dist[i]>0) vertical.push_back(move_dist[i]);
		}
		//横方向への動き
		if(i%2==0){
			if(move_dist[i]>0) horizontal.push_back(move_dist[i]);
		}
	}

	//i回目で座標x=jに到達可能ならば
	//reach_x[i].insert(j)とする
	vector<set<int>> reach_x(horizontal.size()+1);
	reach_x[0].insert(0);
	//ばらまくイメージ
	for(int i=0;i<horizontal.size();i++){
		for(int now_x : reach_x[i]){
			if(now_x + horizontal[i] <= 8000) reach_x[i+1].insert(now_x + horizontal[i]);
			if(now_x - horizontal[i] >= -8000) reach_x[i+1].insert(now_x - horizontal[i]);
		}
	}
	if(*(reach_x[horizontal.size()].lower_bound(x))!=x) return;

	//i回目で座標y=jに到達可能ならば
	//reach_y[i].insert(j)とする
	vector<set<int>> reach_y(vertical.size()+1);
	reach_y[0].insert(0);
	//ばらまくイメージ
	for(int i=0;i<vertical.size();i++){
		for(int now_y : reach_y[i]){
			if(now_y + vertical[i] <= 8000) reach_y[i+1].insert(now_y + vertical[i]);
			if(now_y - vertical[i] >= -8000) reach_y[i+1].insert(now_y - vertical[i]);
		}
	}
	if(*(reach_y[vertical.size()].lower_bound(y))!=y) return;

	ans = "Yes";
}

int main(){
    cin >> s;
    cin >> x >> y;
 
    solve();

    cout << ans << endl;
    return 0;
}