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: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int N_MAX = 8010;

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s;cin >> s;
  s.push_back('T');
  int x,y;cin >> x >> y;
  int v[2][N_MAX];
  int count = 0;
  int index = 0;
  int size = 0;
  while(s[index++] == 'F')--x;

  repp(i,index,s.length()){
    if(s[i] == 'F')++count;
    else{
      v[size&1][size/2] = count;
      count = 0;
      ++size;
    }
  }
  bool x_can = false, y_can = false;
  int y_size = size/2+size&1;
  int x_size = size/2;
  set<int> prev;
  set<int> next;
  prev.insert(0);
  rep(i,y_size){
    for(auto itr = prev.begin(),prev_end = prev.end(); itr != prev_end; ++itr){
      next.insert(*itr + v[0][i]);
      next.insert(*itr - v[0][i]);
    }
    swap(prev,next);
    next.clear();
  }
  for(auto itr = prev.begin(), prev_end = prev.end();itr != prev_end; ++itr) if(*itr == y) y_can = true;

  prev.clear();
  prev.insert(0);
  rep(i,x_size){
    for(auto itr = prev.begin(),prev_end = prev.end(); itr != prev_end; ++itr){
      next.insert(*itr + v[1][i]);
      next.insert(*itr - v[1][i]);
    }
    swap(prev,next);
    next.clear();
  }
  for(auto itr = prev.begin(), prev_end = prev.end();itr != prev_end; ++itr) if(*itr == x) x_can = true;
  YesNo(x_can&&y_can);
  return 0;
}