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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc087.contest.atcoder.jp/tasks/arc087_b>
問題文============================================================
 二次元平面の原点にロボットが置かれています。 最初、ロボットは x 軸の正の向きを向いています。
 
 このロボットに命令列 s が与えられます。 s は次の 2 文字のみからなり、先頭から末尾まで順に実行されます。
 
 F : 今向いている向きに長さ 1 だけ移動する。
 T : 時計回りまたは反時計回りの好きな方向に 90 度だけ向きを変える。
 ロボットの目標は、命令列をすべて実行し終わった後に座標 (x,y) にいることです。
 この目標が達成可能か判定してください。
 
=================================================================

解説=============================================================

================================================================
*/

const int Base = 10000;
bool dpx[4050][2*Base];
bool dpy[4050][2*Base];

void solve(){
    string s; cin >> s;
    int x,y; cin >> x >> y;
    vector<int> xs,ys;
    
    bool dir = true;
    int cnt = 0;
    for(int i = 0; i < s.length();i++){
        if(s[i] == 'T'){
            if(dir){
                xs.push_back(cnt);
            }else{
                ys.push_back(cnt);
            }
            cnt = 0;
            dir = !dir;
        }else{
            cnt++;
        }
    }
    if(dir){
        xs.push_back(cnt);
    }else{
        ys.push_back(cnt);
    }
    
    dpx[1][xs[0] + Base] = true;
    for(int i = 1; i < (int)xs.size();i++){
        for(int j = 0; j < 2*Base;j++){
            if(!dpx[i][j]) continue;
            dpx[i+1][j+xs[i]] = dpx[i+1][j-xs[i]] = true;
        }
    }
    
    dpy[0][Base] = true;
    for(int i = 0; i < (int)ys.size();i++){
        for(int j = 0; j < 2*Base;j++){
            if(!dpy[i][j]) continue;
            dpy[i+1][j+ys[i]] = dpy[i+1][j-ys[i]] = true;
        }
    }
    if(dpx[xs.size()][Base + x] && dpy[ys.size()][Base + y]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    solve();
	return 0;
}