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>();

            work first = new work();
            first.x = 0;
            first.y = 0;
            first.order = s;
            first.muki = 0;
            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 == x && w.y == y)
                        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;


                    if (manhattan(add1.x, add1.y, x, y) <= countF(add1.order))
                        line.Enqueue(add1);
                    if (manhattan(add2.x, add2.y, x, y) <= countF(add2.order)) 
                        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");

        ;
        
    }

    public static int manhattan(int a, int b, int x, int y)
    {
        return Math.Abs(a - x) + Math.Abs(b - y);

    }
    public static int countF(string x)
    {
        int output = 0;
        for (int i = 0; i < x.Length; i++)
        {
            if (x[i] == 'F') output++;
        }
        return output;

    }



}