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)

//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var com = Console.ReadLine();
		var c = com.ToArray();
		var N = c.Length;
		var I = G();
		var dx = new List<int>();
		var dy = new List<int>();
		Action<int,int> f = (d, l) => {
			if (d % 2 == 0) dx.Add(l);
			else dy.Add(l);
		};
		var dir = 0;
		var i = 0;
		while (i < N && c[i] == 'F') i++;
		I[0] -= i;
		while (i < N)
		{
			var l = 0;
			while (i < N && c[i] == 'F') { i++; l++; }
			if (l > 0) f(dir, l);
			while (i < N && c[i] == 'T') { i++; dir++; }
		}
		Console.WriteLine(Calc(dx, I[0]) && Calc(dy, I[1]) ? "Yes" : "No");
	}
	bool Calc(List<int> dx, int sum)
	{
		var s = new HashSet<int>{ 0 };
		foreach (var d in dx)
		{
			var t = new HashSet<int>();
			foreach (var x in s)
			{
				t.Add(x + d);
				t.Add(x - d);
			}
			s = t;
		}
		return s.Contains(sum);
	}
}