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++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x&&x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS*max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x*x + y*y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;


#if 1

static bool dp[2][16000+10];

bool ok( const vector <int>& ud, int goal)
{

	const int S = SZ(ud);
	if (S == 0)
	{
		return goal == 0;
	}

	memset(dp, 0, sizeof(dp));
	const int GETA = 8000+2;
	dp[0][GETA] = true;


	int now;
	int next;
	for (int i=0;i<S;++i)
	{
		now = i % 2;
		next = 1 - now;

		memset(dp[next], 0, sizeof(dp[next]));
		for (int y = -GETA; y <= GETA; y++)
		{
			if (dp[now][y+GETA])
			{
				dp[next][y + GETA + ud[i]] = true;
				dp[next][y + GETA - ud[i]] = true;
			}
		}
	}

	return dp[next][goal + GETA];
}

int main()
{
	string s;

	cin >> s;
	s += 'T';

	int x, y;
	cin >> x >> y;

	vector <int> ud, lr;

	int turn = 0;
	int forward = 0;
	for (int i=0;i<SZ(s);++i)
	{
		if (s[i] == 'T')
		{

			if (turn == 0)
			{
				x -= forward;
			}
			else if (turn % 2 == 1)
			{
				ud.push_back(forward);
			}
			else
			{
				lr.push_back(forward);
			}

			turn++;

			forward = 0;
		}
		else
		{
			forward++;
		}
	}

	if (ok(ud, y) && ok(lr, x))
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}

	return 0;






}

#else

int main()
{
	int N;
	scanf("%d", &N);

	map <int, int> mp;
	for (int i = 0; i < N; ++i)
	{
		int tmp;
		scanf("%d", &tmp);

		mp[tmp]++;
	}

	int ans = 0;

	for (auto& a : mp)
	{
		if (a.second > a.first)
		{
			ans += a.second - a.first;
		}
		else if (a.second < a.first)
		{
			ans += a.second;
		}
	}


	printf("%d\n",ans);

	return 0;

}

#endif