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: Accepted)

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include <unordered_map>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string S; cin >> S;
	int X, Y; cin >> X >> Y;
	queue<int>x, y;
	int N = S.size();
	int cnt = 0;
	int t = 0;
	REP(i, N) {
		if (S[i] == 'F') cnt++;
		if (i == N - 1 || S[i] == 'T') {
			
			if (x.empty() && y.empty()) {
				x.push(cnt);
				y.push(0);
			}
			else if (t % 2) {
				queue<int>tmp;
				unordered_map<int, bool>mp;
				while (!y.empty()) {
					if (!mp[y.front() - cnt]) {
						tmp.push(y.front() - cnt);
						mp[y.front() - cnt] = 1;
					}
					if (!mp[y.front() + cnt]) {
						tmp.push(y.front() + cnt);
						mp[y.front() + cnt] = 1;
					}
					y.pop();
				}
				y = tmp;
			}
			else {
				queue<int>tmp;
				unordered_map<int, bool>mp;
				while (!x.empty()) {
					if (!mp[x.front() - cnt]) {
						tmp.push(x.front() - cnt);
						mp[x.front() - cnt] = 1;
					}
					if (!mp[x.front() + cnt]) {
						tmp.push(x.front() + cnt);
						mp[x.front() + cnt] = 1;
					}
					x.pop();
				}
				x = tmp;
			}
			t++;
			cnt = 0;
		}

	}

	int F = 0;
	while (!x.empty()) {
		if (x.front() == X)F++;
		//cout << x.front() << endl;
		x.pop();
	}
	//cout << endl;
	while (!y.empty()) {
		if (y.front() == Y)F++;
		//cout << y.front() << endl;
		y.pop();
	}
	if (F == 2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}