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.Linq;
using System.Collections.Generic;

namespace ARC087_D___FT_Robot
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver() ? "Yes" : "No");
        }
        static bool solver()
        {
            var s = Console.ReadLine();
            var xy = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var x = xy[0];
            var y = xy[1];

            var moveX = new List<int>();
            var moveY = new List<int>();
            var isX = true;
            var moveCount = 0;
            foreach (char c in s)
            {
                if (c == 'T')
                {
                    if (moveCount > 0)
                    {
                        if (isX) moveX.Add(moveCount); else moveY.Add(moveCount);
                    }
                    isX = !isX;
                    moveCount = 0;
                }
                if (c == 'F') moveCount++;
            }
            if (isX) moveX.Add(moveCount); else moveY.Add(moveCount);

            var differenceX = moveX.Sum() - Math.Abs(x);
            var differenceY = moveY.Sum() - Math.Abs(y);
            if (differenceX < 0 || differenceY < 0) return false;
            if ((differenceX % 2) == 1 || (differenceY % 2) == 1) return false;

            var dpX = new bool[10000, moveX.Count + 1];
            for (int i = 0; i < 8000 + 1; i++) for (int j = 0; j < moveX.Count + 1; j++) dpX[i, j] = false;
            dpX[0, 0] = true;
            for (int move = 1; move < moveX.Count + 1; move++)
            {
                for (int sum = 0; sum < 8000 + 1; sum++)
                {
                    if (dpX[sum, move - 1])
                    {
                        dpX[sum, move] = true;
                        dpX[sum + moveX[move - 1], move] = true;
                    }
                }
            }

            var dpY = new bool[10000, moveY.Count + 1];
            for (int i = 0; i < 8000 + 1; i++) for (int j = 0; j < moveY.Count + 1; j++) dpY[i, j] = false;
            dpY[0, 0] = true;
            for (int move = 1; move < moveY.Count + 1; move++)
            {
                for (int sum = 0; sum < 8000 + 1; sum++)
                {
                    if (dpY[sum, move - 1])
                    {
                        dpY[sum, move] = true;
                        dpY[sum + moveY[move - 1], move] = true;
                    }
                }
            }

            return dpX[differenceX / 2, moveX.Count] && dpY[differenceY / 2, moveY.Count];
        }
    }
}