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: Runtime Error)

#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>
#include <cmath>

using namespace std;
using ll = long long;
// const ll mod =  998244353 ;
const ll mod =  1000000007 ;
const ll inf = 1e18;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

struct Node {
  int a;
  int b;
  Node *child;
  Node(int _a, int _b) : a(_a), b(_b) {
    child = nullptr;
  }
    Node(int _a, int _b, Node *_child) : a(_a), b(_b), child(_child) {
  }
};

bool check(int x, const vector<ll> & a) {
  int tmp[8010*2] = {};
  int *dp;
  dp = tmp + 8000;
  dp[0] = 1;
  REP(i, sz(a)) {
    REP_FROM(j,-8000, 8000) {
      if(dp[j]) {
        dp[j+a[i]] = 1;
        dp[j-a[i]] = 1; 
      }
    }
  }
  // REP_FROM(i, -10, 10) cout << dp[i] << " "; cout << endl;
  return dp[x] == 1;
}
signed main() {
  ios::sync_with_stdio(false);
  string s;
  int x, y;
  cin >> s >> x >> y;
  vector<ll> a, b;
  int start = 0;
  REP(i, sz(s)) {
    if(s[i] == 'F') start++;
    else break;
  }
  x -= start;
  int cnt = 0;
  int rgt = 1;
  REP_FROM(i, start, sz(s)) {
    if(s[i] == 'F') {
      cnt++;
      continue;
    }
    if(cnt) {
      if(rgt) {
        a.push_back(cnt);
      }
      else {
        b.push_back(cnt);
      }
      cnt = 0;
    }
    rgt ^= 1;
  }
  if(cnt) {
    if(rgt) {
        a.push_back(cnt);
    }
    else {
      b.push_back(cnt);
    }
  }
  if(check(x, a) && check(y, b)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}