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 (Clang 3.8.0) (judge verdict: Runtime Error)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int xtable[8000];
int ytable[8000];
int xa[8000];
int ya[8000];
int main() {
    char* s;
    scanf("%s", s);
    // int* xa;
    // int* ya;
    // xa = malloc(4 * strlen(s));
    // ya = malloc(4 * strlen(s));
    int i = 0;
    int j = 0;
    int k = 0;
    int offset = 0;
    int guuki = 1;
    int x,y;
    scanf("%d %d", &x, &y);

    for (k = 0; k < 8000; k++) {
        xtable[k] = 0;
        ytable[k] = 0;
    }

    while (s[i] == 'F') {
        offset += 1;
        i += 1;
    }

    while (s[i] == 'F' || s[i] == 'T'){
        if (guuki == 1){
            if (s[i] == 'F'){
                xa[j] += 1;
                i += 1;
            }
            if (s[i] == 'T'){
                guuki = -1;
                j += 1;
                i += 1;
            }
        }
        if (guuki == -1) {
            if (s[i] == 'F'){
                ya[j] += 1;
                // printf("ya[%d] = %d\n", j, ya[j]);
                i += 1;
            }
            if (s[i] == 'T'){
                guuki = 1;
                i += 1;
            }
        }
    }

    xtable[0] = 1;
    ytable[0] = 1;

    for (k = 0; k < 8000; k++) {
        for (j = 0; j < 8000; j++) {
            if (xtable[j] == 1 && j + xa[k] < 8000)
                xtable[j + xa[k]] = 1;
        }
    }

    for (k = 0; k < 8000; k++) {
        for (j = 0; j < 8000; j++) {
            if (ytable[j] == 1 && j + ya[k] < 8000)
                ytable[j + ya[k]] = 1;
        }
    }


    int xsum = 0;
    int ysum = 0;
    int xcheck = 0;
    int ycheck = 0;
    x = x - offset;

    for (i = 0; i < 8000; i++){
        xsum += xa[i];
        ysum += ya[i];
    }


    for (i = 0; i < 8000; i++){
        if (xtable[i] == 1){
            if (abs((xsum - i) - i) == abs(x))
                xcheck = 1;
        }
    }

    for (i = 0; i < 8000; i++){
        if (ytable[i] == 1){
            if (abs((ysum - i) - i) == abs(y))
                ycheck = 1;
        }
    }

    if (xcheck == 1 && ycheck == 1)
        printf("Yes\n");
    else
        printf("No\n");
    // printf("%c %lu\n", s[0], strlen(s));
    // printf("%d %d\n", x, y);
    // printf("%d %d %d\n", xsum, ysum, ya[1]);
    return 0;
}