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;
using System.Collections.Generic;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using static System.Console;
using static System.Math;
using  static Ex;
class Simple {
    void Solve() {
        //input
        var s = io.String;
        var x = io.Int;
        var y = io.Int;
        
        //cal
        var ans    = "";
        var offset = 8000;
        var size   = offset * 2;        
        var ss     = s.Split('T').Select(str=>str.Length).ToArray();
        var xLis   = ss.Where((v, i) => i % 2 == 0).ToArray();
        var yLis   = ss.Where((v, i) => i % 2 != 0).ToArray();
        Func <bool, string> Yn = (f) => f ? "Yes" : "No";
        if(yLis.Length != 0 /* && xLis.length == 1*/) {
            var xDp = new bool[xLis.Length, size];
            var yDp = new bool[yLis.Length, size];
            xDp[0, 0 + xLis.First() + offset] = true;
            yDp[0, 0 + yLis.First() + offset] = true;
            yDp[0, 0 - yLis.First() + offset] = true;            
            FOR(1, xLis.Length, i => {            
                size.REP(j => {
                    xDp[i, j] = (j - xLis[i] > 0    && xDp[i - 1, j - xLis[i]]) ||
                                (j + xLis[i] < size && xDp[i - 1, j + xLis[i]]);
                });                                    
            });
            FOR(1, yLis.Length, i => {
                size.REP(j => {
                    yDp[i, j] = (j - yLis[i] > 0    && yDp[i - 1, j - yLis[i]]) ||
                                (j + yLis[i] < size && yDp[i - 1, j + yLis[i]]);
                });
            });
            WriteLine(Yn(xDp[xLis.Length - 1, x + offset] && 
                         yDp[yLis.Length - 1, y + offset]));
        } else {
            WriteLine(Yn(xLis.First() == x && y == 0));
        }
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream();
    private void Stream() {
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //SetIn(exStdIn);
        Solve();
        io.Flush();
    }
}
class SimpleIO {
    string[] _nextBuffer;
    int _bufferCnt;
    char[] cs = new char[] {' ', '"', ','};
    StreamWriter sw = new StreamWriter(OpenStandardOutput()) {
#if DEBUG
        AutoFlush = true
#else
        AutoFlush = false
#endif
    };
    public SimpleIO() {
        _nextBuffer = new string[0];
        _bufferCnt = 0;
        SetOut(sw);
    }
    string Next() {
        if(_bufferCnt < _nextBuffer.Length)
            return _nextBuffer[_bufferCnt++];
        var st = ReadLine();
        while(st == "")
            st = ReadLine();
        _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        _bufferCnt = 0;
        return _nextBuffer[_bufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void Flush() => Out.Flush();
}
static class Ex {
    public static void REP(this int n, Action <int> act) {
        for(var i = 0; i < n; ++i)
            act(i);
    }
    public static void FOR(int a, int b, Action <int> act) {
        for(var i = a; i < b; ++i)
            act(i);
    }
}