def main():

    order = [len(el) for el in list(map(str, input().rstrip().split("T")))]

    x_points = {order[0]}

    y_points = {0}

    for val in order[2::2]:

        plus_val = {x + val for x in list(x_points)}

        minus_val = {x - val for x in list(x_points)}

        x_points = plus_val | minus_val

    for val in order[1::2]:

        plus_val = {y + val for y in list(y_points)}

        minus_val = {y - val for y in list(y_points)}

        y_points = plus_val | minus_val

    target_x, target_y = list(map(int, input().split()))

    if target_x in x_points and target_y in y_points:

        print("Yes")

    else:

        print("No")



if __name__ == "__main__":

    main()

import numpy as np

def main():

    order = [len(el) for el in list(map(str, input().rstrip().split("T")))]

    x, y = list(map(int, input().split()))

    order_x = order[2::2]

    order_y = order[1::2]

    L_x, L_y = len(order_x), len(order_y)

    n = 10000

    dp_x = [np.zeros(2*n, dtype=np.bool) for _ in range(L_x + 1)]

    dp_y = [np.zeros(2*n, dtype=np.bool) for _ in range(L_y + 1)]

    dp_x[0][n + order[0]] = True

    dp_y[0][n] = True

    for i, d in enumerate(order_x):

        dp_x[i+1][d:] |= dp_x[i][:2*n-d]

        dp_x[i+1][:2*n-d] |= dp_x[i][d:]

    for i, d in enumerate(order_y):

        dp_y[i+1][d:] |= dp_y[i][:2*n-d]

        dp_y[i+1][:2*n-d] |= dp_y[i][d:]

    if dp_x[L_x][n + x] and dp_y[L_y][n + y]:

        print("Yes")

    else:

        print("No")



if __name__ == "__main__":

    main()

def main():
    order = [len(el) for el in list(map(str, input().rstrip().split("T")))]
    x_points = {order[0]}
    y_points = {0}
    for val in order[2::2]:
        plus_val = {x + val for x in list(x_points)}
        minus_val = {x - val for x in list(x_points)}
        x_points = plus_val | minus_val
    for val in order[1::2]:
        plus_val = {y + val for y in list(y_points)}
        minus_val = {y - val for y in list(y_points)}
        y_points = plus_val | minus_val
    target_x, target_y = list(map(int, input().split()))
    if target_x in x_points and target_y in y_points:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

import numpy as np


def main():
    order = [len(el) for el in list(map(str, input().rstrip().split("T")))]
    x, y = list(map(int, input().split()))
    order_x = order[2::2]
    order_y = order[1::2]
    L_x, L_y = len(order_x), len(order_y)
    n = 10000
    dp_x = [np.zeros(2 * n, dtype=np.bool) for _ in range(L_x + 1)]
    dp_y = [np.zeros(2 * n, dtype=np.bool) for _ in range(L_y + 1)]
    dp_x[0][n + order[0]] = True
    dp_y[0][n] = True
    for i, d in enumerate(order_x):
        dp_x[i + 1][d:] |= dp_x[i][: 2 * n - d]
        dp_x[i + 1][: 2 * n - d] |= dp_x[i][d:]
    for i, d in enumerate(order_y):
        dp_y[i + 1][d:] |= dp_y[i][: 2 * n - d]
        dp_y[i + 1][: 2 * n - d] |= dp_y[i][d:]
    if dp_x[L_x][n + x] and dp_y[L_y][n + y]:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

+import numpy as np + + -    x_points = {order[0]} -    y_points = {0} -    for val in order[2::2]: -        plus_val = {x + val for x in list(x_points)} -        minus_val = {x - val for x in list(x_points)} -        x_points = plus_val | minus_val -    for val in order[1::2]: -        plus_val = {y + val for y in list(y_points)} -        minus_val = {y - val for y in list(y_points)} -        y_points = plus_val | minus_val -    target_x, target_y = list(map(int, input().split())) -    if target_x in x_points and target_y in y_points: +    x, y = list(map(int, input().split())) +    order_x = order[2::2] +    order_y = order[1::2] +    L_x, L_y = len(order_x), len(order_y) +    n = 10000 +    dp_x = [np.zeros(2 * n, dtype=np.bool) for _ in range(L_x + 1)] +    dp_y = [np.zeros(2 * n, dtype=np.bool) for _ in range(L_y + 1)] +    dp_x[0][n + order[0]] = True +    dp_y[0][n] = True +    for i, d in enumerate(order_x): +        dp_x[i + 1][d:] |= dp_x[i][: 2 * n - d] +        dp_x[i + 1][: 2 * n - d] |= dp_x[i][d:] +    for i, d in enumerate(order_y): +        dp_y[i + 1][d:] |= dp_y[i][: 2 * n - d] +        dp_y[i + 1][: 2 * n - d] |= dp_y[i][d:] +    if dp_x[L_x][n + x] and dp_y[L_y][n + y]: