Language: C++

#include <iostream>
#include <vector>

using namespace std;

using ll = long long;

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	int x, y;
	cin >> x >> y;
	
	vector<int> xMove, yMove;
	ll xMoveNum = 0, yMoveNum = 0;
	int xcnt = 0, ycnt = 0;
	bool directX = true; // falseのときy軸方向
	bool existT = false;
	REP(i, s.length()) {
		if (s[i] == 'T') {
			
			if (directX) {
				if (xcnt != 0) {
					if (!existT) {
						xMove.push_back(xcnt);
						xMoveNum += 1;
					} else {
						if (xMove.size() == 0) {
							int xgo = xcnt, xback = -xcnt;
							xMove.push_back(xgo);
							xMove.push_back(xback);
							xMoveNum += 2;
						} else {
							REP(j, xMove.size()) {
								int xgo = xMove[j] + xcnt, xback = xMove[j] - xcnt;
								xMove.push_back(xgo);
								xMove.push_back(xback);
								xMoveNum += 2;
							}
						}
					}
				}
				xcnt = 0;
				directX = false;
			} else {
				if (ycnt != 0) {
					if (yMove.size() == 0) {
						int ygo = ycnt, yback = -ycnt;
						yMove.push_back(ygo);
						yMove.push_back(yback);
						yMoveNum += 2;
					} else {
						REP(j, yMove.size()) {
							int ygo = yMove[j] + ycnt, yback = yMove[j] - ycnt;
							yMove.push_back(ygo);
							yMove.push_back(yback);
							yMoveNum += 2;
						}
					}
				}
				ycnt = 0;
				directX = true;
			}
			
			existT = true;
//			REP(i, xMove.size()) cout << xMove[i] << endl;
//			cout << endl;
//			REP(i, yMove.size()) cout << yMove[i] << endl;
		}
		if (s[i] == 'F') {
			
			if (directX) {
				xcnt++;
			} else {
				ycnt++;
			}
			
		}

//		cout << xcnt << " " << ycnt << endl;
		if (i == s.length() - 1) {
//			cout << xMove.size() << " " << yMove.size() << endl;
			if (directX) {
				if (xcnt != 0) {
					if (!existT) {
						xMove.push_back(xcnt);
					} else {
						if (xMove.size() == 0) {
							int xgo = xcnt, xback = -xcnt;
							xMove.push_back(xgo);
							xMove.push_back(xback);
						} else {
//							for (int j = 0; j < xMoveNum; ++j) {
//								cout << j << endl;
//								int xgo = xMove[j] + xcnt, xback = xMove[j] - xcnt;
//								xMove.push_back(xgo);
//								xMove.push_back(xback);
//							}
							REP(j, xMoveNum) {
//								cout << j << endl;
								int xgo = xMove[j] + xcnt, xback = xMove[j] - xcnt;
								xMove.push_back(xgo);
								xMove.push_back(xback);
							}
						}
					}
				}
//				xcnt = 0;
//				directX = false;
			} else {
				if (ycnt != 0) {
					if (yMove.size() == 0) {
						int ygo = ycnt, yback = -ycnt;
						yMove.push_back(ygo);
						yMove.push_back(yback);
					} else {
						REP(j, yMoveNum) {
							int ygo = yMove[j] + ycnt, yback = yMove[j] - ycnt;
							yMove.push_back(ygo);
							yMove.push_back(yback);
						}
					}
				}
//				ycnt = 0;
//				directX = true;
			}
		}
	}
	
	if (xMoveNum == 0) xMove.push_back(0);
	if (yMoveNum == 0) yMove.push_back(0);
	
	sort(xMove.begin(), xMove.end());
	sort(yMove.begin(), yMove.end());

//	REP(i, xMove.size()) cout << xMove[i] << endl;
//	cout << endl;
//	REP(i, yMove.size()) cout << yMove[i] << endl;
	
	if (lower_bound(xMove.begin(), xMove.end(), x) - xMove.begin() < xMove.size()) {
		if (lower_bound(yMove.begin(), yMove.end(), y) - yMove.begin() < yMove.size()) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	} else {
		cout << "No" << endl;
	}
	
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:140:9: error: 'sort' was not declared in this scope; did you mean 'short'?
  140 |         sort(xMove.begin(), xMove.end());
      |         ^~~~
      |         short