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)

#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

string s;
int x,y;
vector<int> dir_x;
vector<int> dir_y;

bool dpx[40000][3000];
bool dpy[40000][3000];
int main(){
	cin>>s;
	//cout<<s.size()<<endl;
	cin>>x>>y;
	REP(i,40000){
		REP(j,3000){
		dpx[i][j]=false;
		dpy[i][j]=false;
		}
	}
	int count=0;
	int dir=0;
	int flag=1;
	for(int i=0;i<s.size();i++){
		if(s[i]=='F'){
			count++;
		}else{
			if(count!=0){
				if(dir){
					dir_y.push_back(count);
				}else{
					if(flag) x-=count;
					else dir_x.push_back(count);
				}
			}
			dir=~dir;
			count=0;
			flag=0;
		}
	}
	if(count!=0){
		if(dir){
			dir_y.push_back(count);
		}else{
			if(flag)x-=count;
			else dir_x.push_back(count);
		}
	}
	dpx[20000][0]=true;
	for(int i=0;i<dir_x.size();i++){
		for(int j=0;j<40000;j++){
			if(dpx[j][i]){
				dpx[j+dir_x[i]][i+1]=true;
				dpx[j-dir_x[i]][i+1]=true;
			}
		}
	}
	dpy[20000][0]=true;
	for(int i=0;i<dir_y.size();i++){
		for(int j=0;j<40000;j++){
			if(dpx[j][i]){
				dpx[j+dir_y[i]][i+1]=true;
				dpx[j-dir_y[i]][i+1]=true;
			}
		}
	}
	//cout<<x<<" "<<y<<endl;
	if(dpx[20000+x][dir_x.size()]&&dpy[20000+y][dir_y.size()]){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}