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>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


bool dx[2][2*8000], dy[2][2*8000];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    int x, y;
    cin >> S >> x >> y;
    vector<vector<int>> a(2);
    int d = 0;
    REP(i,S.size()){
        int t=0;
        while(S[i]=='F'&&i<S.size()) t++,i++;
        a[d].push_back(t);
        d = 1-d;
    }
    int g = 8000;
    REP(i,2) REP(j,2*g){
        dx[i][j] = false;
        dy[i][j] = false;
    }
    dx[0][g] = true, dy[0][g] = true;
    REP(i,a[0].size()){
        REP(j,2*g){
            if(dx[i%2][j]){
                dx[(i+1)%2][j+a[0][i]] = true;
                if(i > 0) dx[(i+1)%2][j-a[0][i]] = true;
                dx[i%2][j] = false;
            }
        }
    }
    REP(i,a[1].size()){
        REP(j,2*g){
            if(dy[i%2][j]){
                dy[(i+1)%2][j+a[1][i]] = true;
                dy[(i+1)%2][j-a[1][i]] = true;
                dy[i%2][j] = false;
            }
        }
    }
    int a0 = a[0].size(), a1 = a[1].size();
    if(dx[a0%2][g+x] && dy[a1%2][g+y]) cout << "Yes" << endl;
    else cout << "No" << endl;
}