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

public class Program
{

    public void Proc()
    {
        string inpt = Reader.ReadLine();
        int[] goalPos = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();


        int xMoveRemain = 0;
        int yMoveRemain = 0;

        string[] tmp = inpt.Split('T');
        List<int> xMoveList = new List<int>();
        List<int> yMoveList = new List<int>();
        for (int i = 0; i < tmp.Length; i++) {
            if(i%2==0) {
                xMoveRemain += tmp[i].Length;
                xMoveList.Add(tmp[i].Length);
            } else {
                yMoveRemain += tmp[i].Length;
                yMoveList.Add(tmp[i].Length);
            }
        }

        bool xReach = CanReach(1, xMoveList[0], goalPos[0], xMoveList);
        dic = new Dictionary<int, Dictionary<int, bool>>();
        bool yReach = CanReach(0, 0, goalPos[1], yMoveList);
        Console.WriteLine((xReach&&yReach)?"Yes":"No");
    }

    private Dictionary<int, Dictionary<int, bool>> dic = new Dictionary<int, Dictionary<int, bool>>();
    private bool CanReach(int idx, int pos, int goal, List<int> mv) {
        if(idx>=mv.Count) {
            if(pos == goal) {
                return true;
            }
            return false;
        }
        if(!dic.ContainsKey(idx)) {
            dic.Add(idx, new Dictionary<int, bool>());
        }
        if(dic[idx].ContainsKey(pos)) {
            return dic[idx][pos];
        }
        bool ans = false;
        ans = ans || CanReach(idx + 1, pos + mv[idx], goal, mv);
        ans = ans || CanReach(idx + 1, pos - mv[idx], goal, mv);
        dic[idx][pos] = ans;
        return ans;
    }


    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"


TTTT
1 0


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}