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 System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var str = ReadLine();
        var xy = Input.ar;
        var li = new[] { new List<int>(), new List<int>() };
        var s = str.Trim().Split('T');
        for (var i = 0; i < s.Length; i++)
            if (i % 2 == 0)
                li[0].Add(s[i].Length);
            else li[1].Add(s[i].Length);
        for(var i=0;i<2;i++)
        {
            var dp = Enumerable.Repeat(0, li[i].Count).Select(v => new HashSet<int>()).ToArray();
            if (i == 0) dp[0].Add(li[i][0]);
            else
            {
                if (li[1].Count == 0)
                {
                    WriteLine(xy[1] == 0 ? "Yes" : "No");
                    return;
                }
                dp[0].Add(li[i][0]);
                dp[0].Add(-li[i][0]);
            }
            for(var j=1;j<li[i].Count;j++)
                for(var h=-str.Length;h<=str.Length;h++)
                    if (dp[j-1].Contains(h))
                    {
                        if (-str.Length <= h - li[i][j])
                            dp[j].Add(h - li[i][j]);
                        if (str.Length >= h + li[i][j])
                            dp[j].Add(h + li[i][j]);
                    }
            if (!dp[li[i].Count-1].Contains(xy[i]))
            {
                WriteLine("No");
                return;
            }
        }
        WriteLine("Yes");
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static string[] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read).ToArray();
    public static int[][] twodim(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] twodimL(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-11;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}