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 <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
string str,sx,sy;
int x,y;
vector <int> vx,vy;
int tx[20005],ty[20005];
void work(){
	for (int i=0;i<sx.size();i++){
		x=x*10+sx[i]-'0';
	}
	for (int i=0;i<sy.size();i++){
		y=y*10+sy[i]-'0';
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin>>str;
	str+='T';
	cin>>sx>>sy;
	if (sx.size()>4 || sy.size()>4){
		cout<<"NO";
		return 0;
	}
	work();
	int cnt=0,k=0;
	for (int i=0;i<str.length();i++){
		if (str[i]=='T'){
			if (k%2==0){
				vx.push_back(cnt); 
			}else{
				vy.push_back(cnt); 
			}
			cnt=0;
			k++;
		}else{
			cnt++;
		}
	}
	for (int i=0;i<=17000;i++) tx[i]=ty[i]=-2;
	tx[8500]=-1;
	for (int i=0;i<vx.size();i++){
		for (int j=0;j<=17000;j++){
			if (tx[j]==i-1){
				tx[j-vx[i]]=i;
				tx[j+vx[i]]=i;
			}
		}
	}
	ty[8500]=-1;
	for (int i=0;i<vy.size();i++){
		for (int j=0;j<=17000;j++){
			if (ty[j]==i-1){
				ty[j-vy[i]]=i;
				ty[j+vy[i]]=i;
			}
		}
	}
	if (tx[x+8500]==vx.size()-1 && ty[y+8500]==vy.size()-1) cout<<"Yes"; else cout<<"No";
	return 0;
}