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 PyPy3 (2.4.0) (judge verdict: Runtime Error)

s = input()
x, y = map(int, input().split())
if s[0] == "F":
    x_choku = True
else:
    x_choku = False
# susumu = s.count("F")
# if susumu % 2 != (x + y) % 2:
#     print("No")
#     exit()
# if susumu < (x + y):
#     print("No")
#     exit()
x_houkou = True
cnt = 0
X = []
Y = []
for w in s:
    if w == "F":
        cnt += 1
    else:
        if x_houkou:
            X.append(cnt)
            cnt = 0
            x_houkou = False
        else:
            Y.append(cnt)
            cnt = 0
            x_houkou = True
if cnt > 0:
    if x_houkou:
        X.append(cnt)
    else:
        Y.append(cnt)
if x_choku:
    x -= X[0]
    X = X[1::]


x_ok = False
y_ok = False
if not X:
    if x == 0:
        x_ok = True
    else:
        print("No")
        exit()
if not Y:
    if y == 0:
        y_ok = True
    else:
        print("No")
        exit()

x = abs(x)
y = abs(y)
x_num = len(X)
y_num = len(Y)
if not x_ok:
    dp1 = [0] * (8000 + 1)
    dp2 = [0] * (8000 + 1)
    dp1[0] = 1
    for j in range(x_num):
        if j % 2 == 0:
            t = X[j]
            for i in range(8000, -1, -1):
                if dp1[i] == 1:
                    if i + t <= 8000:
                        dp2[i + t] = 1
                    if i - t >= 0:
                        dp2[i + t] = 1
        else:
            t = Y[j]
            for i in range(8000, -1, -1):
                if dp2[i] == 1:
                    if i + t <= 8000:
                        dp1[i + t] = 1
                    if i - t >= 0:
                        dp1[i + t] = 1
    if x_num % 2 == 1:
        x_ok += dp2[x]
    else:
        x_ok += dp1[x]

if not y_ok:
    dp1 = [0] * (8000 + 1)
    dp2 = [0] * (8000 + 1)
    dp1[0] = 1
    for j in range(y_num):
        if j % 2 == 0:
            t = Y[j]
            for i in range(8000, -1, -1):
                if dp1[i] == 1:
                    if i + t <= 8000:
                        dp2[i + t] = 1
                    if i - t >= 0:
                        dp2[i + t] = 1
        else:
            t = Y[j]
            for i in range(8000, -1, -1):
                if dp2[i] == 1:
                    if i + t <= 8000:
                        dp1[i + t] = 1
                    if i - t >= 0:
                        dp1[i + t] = 1
    if y_num % 2 == 1:
        y_ok += dp2[y]
    else:
        y_ok += dp1[y]

if x_ok and y_ok:
    print("Yes")
else:
    print("No")