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: Runtime Error)

#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

bool check(vector<int> X, int x){
	int MAX = 18001;
	int cen = MAX/2;
	vector<bool> pos(MAX,false);
	pos[cen] = true;//原点0にいる。
	x += cen;
	int size = X.size();
	for(int i=0;i<size;++i){
		vector<bool> next(MAX,false);
		int move = X[i];
		for(int j=0;j<MAX;++j){
			if( pos[j] ){
				next[j+move] = true;
				next[j-move] = true;
			}
		}
		pos = next;
	}
	return pos[x];
}
void solve(){
	string str;
	int x,y;
	cin>>str>>x>>y;
	int size = str.size();
	vector<int> X,Y;
	int dir = 0;
	int count = 0;
	int pos = 0;
	for(pos;pos<size;pos++){
		if( str[pos]=='F' ){
			--x;
		}else{
			break;
		}
	}
	
	for(int i=pos;i<size;++i){
		if( str[i] == 'T' ){
			if( count == 0 ){
			}else if( dir&1){
				Y.push_back( count );
			}else{
				X.push_back( count );
			}
			count = 0;
			dir = (dir+1)%4;
		}else{//F
			++count;
		}
	}
	if( count == 0 ){
	}else if( dir&1){
		Y.push_back( count );
	}else{
		X.push_back( count );
	}

	if( check( X,x ) == false){
		cout << "No" << endl;
		return;
	}
	if( check( Y,y ) == false){
		cout << "No" << endl;
		return;
	}
	cout << "Yes" << endl;
}
#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()