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 Python (3.4.3) (judge verdict: Wrong Answer)

s=input()
x,y=[int(i) for i in input().split()]
count=0
x_v=[]
y_v=[]

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            if count!=0:
                x_v.append(count)
            dir=0
            count=0

        else:
            if count!=0:
                y_v.append(count)
            dir=1
            count=0

    if i==len(s)-1:
        if dir==1 and count!=0:
            x_v.append(count)
        elif dir==0 and count!=0:
            y_v.append(count)

number_x=2*sum(x_v)
x_check=0
dp_x=[[0 for i in range(number_x+1)] for j in range(len(x_v))]
if sum(x_v)!=0:
    dp_x[0][x_v[0]+sum(x_v)]=1

for i in range(len(x_v)-1):
    for j in range(number_x+1):
        if dp_x[i][j]==1:
            if j+x_v[i+1]<=number_x+1:
                dp_x[i+1][j+x_v[i+1]]=1
            if j-x_v[i+1]>=0:
                dp_x[i+1][j-x_v[i+1]]=1

if sum(x_v)!=0 and sum(x_v)>=abs(x):
  if dp_x[len(x_v)-1][x+sum(x_v)]==1:
    x_check=1


elif sum(x_v)==0:
  if x==0:
    x_check=1  



number_y=sum(y_v)
y_check=0
dp_y=[[0 for i in range(number_y+1)] for j in range(len(y_v))]
if sum(y_v)!=0:
    dp_y[0][y_v[0]]=1

if sum(y_v)!=0 and x_check==1:
  for i in range(len(y_v)-1):
    for j in range(number_y+1):
          if dp_y[i][j]==1:
              dp_y[i+1][j+y_v[i+1]], dp_y[i+1][abs(j-y_v[i+1])]=1,1

if sum(y_v)!=0 and sum(y_v)>=abs(y):
  if dp_y[len(y_v)-1][abs(y)]==1:
    y_check=1
elif sum(y_v)==0:
  if y==0:
    y_check=1

if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")