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 <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>


using namespace std;
string yn(bool a)
{
  if (a){return "Yes";}
  else{return "No";}
}

int main()
{
  ios::sync_with_stdio(false);
  string s;
  int x,y;
  cin>>s>>x>>y;
  vector<int> a,b;
  bool f=1;
  int tmp=0;
  for(auto itr=s.begin();itr !=s.end();itr++)
  {
    if(*itr=='F'){tmp++;}
    else {
      if(f){a.push_back(tmp);}
      else{b.push_back(tmp);}
      f=!f;
    tmp=0;
  }

  }
  if(f){a.push_back(tmp);}
  else{b.push_back(tmp);}
  x-=a[0];
  x=abs(x);
  y=abs(y);
  a.erase(a.begin());
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  int suma=0,sumb=0;
  for(auto itr=a.begin();itr !=a.end();itr++)
  {
    //cout<<*itr<<endl;
    suma+=*itr;
  }
  for(auto itr=b.begin();itr !=b.end();itr++)
  {
    sumb+=*itr;
    //cout<<*itr<<endl;
  }
  int flag=0;
  //cout<<x<<' '<<y<<' '<<suma<<' '<<sumb;
  if((suma-x)%2 or (sumb-y)%2){flag=0;}
  else
  {
    x=(suma-x)/2;
    y=(sumb-y)/2;
    //cout<<x<<' '<<y;
    vector<int> dpx(8001),dpy(8001);
    for(int i=0;i<x+1;i++){dpx[i]=0;dpy[i]=0;}
    dpx[0]=1;dpx[suma-x]=1;
    dpy[0]=1;dpy[sumb-y]=1;
    for(auto itr1=a.begin();itr1 !=a.end();itr1++)
    {
      if(dpx[x]!=0 or dpx[suma-x]!=0){flag+=1;break;}
      for(int i=0;i<suma+1;i++)
      {
        if(dpx[i]==1){dpx[i+*itr1]=1;}
      }
      if(dpx[x]!=0 or dpx[suma-x]!=0){flag+=1;break;}

    }
    //cout<<flag<<endl;
    for(auto itr2=b.begin();itr2 !=b.end();itr2++)
    {
      if(dpy[y]!=0 or dpy[sumb-y]!=0){flag+=1;break;}
      for(int i=0;i<sumb+1;i++)
      {
        if(dpy[i]==1){dpy[i+*itr2]=1;}
      }
      if(dpy[y]!=0 or dpy[sumb-y]!=0){flag+=1;break;}
    }
  }
  cout<<yn(flag==2)<<endl;



  return 0;

}