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# (Mono 4.6.2.0) (judge verdict: Time Limit Exceeded)

using System;
using System.Collections.Generic;

public class Hello
{
    public struct work
    {
        public string order;
        public int x;
        public int y;
        public int muki;
    }
    public static int flag = 0;
    public static void Main()
    {


        bool can = false;

        string s = Console.ReadLine();
        string temp = Console.ReadLine();
        int x = int.Parse(temp.Split(' ')[0]);
        int y = int.Parse(temp.Split(' ')[1]);
        string revs="";
        char[] temp2 = s.ToCharArray();
        Array.Reverse(temp2);
        for (int i = 0; i < temp2.Length; i++)
        {
            revs += temp2[i];
        }

        Queue<work> line = new Queue<work>();
        for (int i = 0; i < 4; i++)
        {
            work first = new work();
            first.x = x;
            first.y = y;
            first.order = revs;
            first.muki = i;
            line.Enqueue(first);
        }
        while (line.Count > 0)
        {
            if (can)
            {
                break;
            }
            work w = line.Dequeue();
            
            while (true)//Tを読み込むかorderがなくなるまで
            {

                if (w.order == "" || w.order == null)
                {
                    if (w.x == 0 && w.y == 0 && w.muki ==0)
                        can = true;
                    break;
                }
                else if (w.order[0]=='T')
                {
                    w.order = w.order.Substring(1, w.order.Length - 1);
                    work add1 = new work();
                    work add2 = new work();

                    add1.x = w.x;
                    add1.y = w.y;
                    add2.x = w.x;
                    add2.y = w.y;

                    add1.muki = (w.muki + 1) % 4;
                    add2.muki = (w.muki + 3) % 4;

                    add1.order = w.order;
                    add2.order = w.order;

                    line.Enqueue(add1);
                    line.Enqueue(add2);
                    break;
                }
                else
                {

                    if (w.muki == 0) w.x--;
                    if (w.muki == 1) w.y--;
                    if (w.muki == 2) w.x++;
                    if (w.muki == 3) w.y++;

                    w.order = w.order.Substring(1, w.order.Length - 1);

                }
        
            }



        }

        if (can)
            Console.WriteLine("Yes");
        else Console.WriteLine("No");

        ;
        
    }



}