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: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    private struct Pair<T> { public T x, y; public Pair(T xx, T yy) { x = xx; y = yy; } }
    private static int[] dx = { 1, 0, -1, 0 };
    private static int[] dy = { 0, -1, 0, 1 };
    public static void Main()
    {
        string s = NextString();
        //string s = "";
        //for (int i = 0; i < 8000; i++) s += "F";
        int x = NextInt();
        int y = NextInt();
        bool[] xdp = new bool[16010];
        bool[] ydp = new bool[16010];
        xdp[8000] = ydp[8000] = true;

        int f = 0;
        int L = 0;
        for (f = 0; f < s.Length && s[f] == 'F'; f++) L++;
        xdp[8000] = false;
        xdp[8000 + L] = true;

        List<int> xlist = new List<int>();
        List<int> ylist = new List<int>();
        bool varti = true;
        L = 0;
        for (int i = f; i < s.Length; i++)
        {
            if (s[i] == 'F') { L++; }
            else
            {
                if (varti) { xlist.Add(L); varti = false; }
                else { ylist.Add(L); varti = true; }
                L = 0;
            }
        }
        if (s[s.Length - 1] == 'F')
        {
            if (varti) { xlist.Add(L); }
            else { ylist.Add(L); }
        }
        foreach (int d in xlist)
        {
            bool[] nxdp = new bool[16010];
            for (int i = 16000; i >= 0; i--)
                if (xdp[i] && i + d <= 16000) { nxdp[i + d] = true; }
            for (int i = 0; i <= 16000; i++)
                if (xdp[i] && i - d >= 0) nxdp[i - d] = true;
            xdp = nxdp;
        }
        foreach (int d in ylist)
        {
            bool[] nxdp = new bool[16010];
            for (int i = 16000; i >= 0; i--)
                if (ydp[i] && i + d <= 16000) nxdp[i + d] = true;
            for (int i = 0; i <= 16000; i++)
                if (ydp[i] && i - d >= 0) nxdp[i - d] = true;
            ydp = nxdp;
        }

        //for (int i = 0; i <= 16000; i++)
        //    if (xdp[i]) Console.WriteLine(i - 8000);
        Console.WriteLine((xdp[x + 8000] && ydp[y + 8000] ? "Yes" : "No"));
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}