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: Wrong Answer)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
using System.Text;
using static System.Console;
using static System.Math;
class Simple {
    void Solve() {
        //input        
        var s = io.String;
        var x = io.Int;
        var y = io.Int;
        //cal        
        var xLis = new List <int>();
        var yLis = new List <int>();
        var isHolizontal = true;
        var steps = 0;
        Func <char, bool> isTurn = (c) => c == 'T';
        foreach(var c in s.ToCharArray()) {
            if(isTurn(c)) {
                if(steps != 0) {
                    if(isHolizontal) {
                        xLis.Add(steps);
                    } else {
                        yLis.Add(steps);
                    }
                    steps = 0;
                }
                isHolizontal = !isHolizontal;
            } else {
                steps++;
            }
        }
        if(isHolizontal) {
            xLis.Add(steps);
        } else {
            yLis.Add(steps);
        }
        var size = 10000;
        var xDp = new bool[size * 2];
        var yDp = new bool[size * 2];
        xDp[0 + size] = true;
        yDp[0 + size] = true;
        foreach(var v in xLis) {
            xDp.Length.REP(i => {
                if(xDp[i]) {
                    if(i - v >= 0) {
                        xDp[i - v] = true;
                    }
                    if(i + v < xDp.Length) {
                        xDp[i + v] = true;
                    }
                    xDp[i] = false;
                }
            });
        }
        foreach(var v in yLis) {
            yDp.Length.REP(i => {
                if(yDp[i]) {
                    if(i - v >= 0) {
                        yDp[i - v] = true;
                    }
                    if(i + v < yDp.Length) {
                        yDp[i + v] = true;
                    }
                    yDp[i] = false;
                }
            });
        }        
        
        var ans = xDp[size + x] && yDp[size + y];
        //ret
        WriteLine(ans ? "Yes" : "No");
    }
    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);
    }
}