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 JavaScript (node.js v5.12) (judge verdict: Wrong Answer)

// inputに入力データ全体が入る
function Main(input) {
	// ABC082D
	var line = input.split("\n");
	var s = line[0];
	var tmp = line[1].split(" ");

	var forward = s.split("T");

	var dest = [Number(tmp[0]), Number(tmp[1])];

	var dx = [];
	var dy = [];
	for(var i = 0; i < forward.length; i++){
		if(i%2 === 0){
			dx.push(forward[i].length);
		} else{
			dy.push(forward[i].length);
		}
	}

	var x = [];
	var y = [];
	var xflg = false;
	var yflg = false;

	loopx : for(var j = 0; j < dx.length; j++){
		x[j] = [];
		if(j === 0){
			x[j].push(dx[j]);
			if(dx.length === 1 && dx[0] === dest[0]) xflg = true;
		} else if(j === dx.length - 1){
			for(var k = 0; k < x[j-1].length; k++){
				if(x[j-1][k]+dx[j] === dest[0] || x[j-1][k]-dx[j] === dest[0]){
					xflg = true;
					break loopx;
				}
			}
		} else{
			for(var k = 0; k < x[j-1].length; k++){
				x[j].push(x[j-1][k]+dx[j]);
				if(dx[j] !== 0) x[j].push(x[j-1][k]-dx[j]);
			}
		}
	}

	loopy : for(var j = 0; j < dy.length; j++){
		y[j] = [];
		if(j === 0){
			y[j].push(dy[j]);
			if(dy.length === 1 && dy[0] === dest[1]) yflg = true;
		} else if(j === dy.length - 1){
			for(var k = 0; k < y[j-1].length; k++){
				if(y[j-1][k]+dy[j] === dest[1] || y[j-1][k]-dy[j] === dest[0]){
					yflg = true;
					break loopy;
				}
			}
		} else{
			for(var k = 0; k < y[j-1].length; k++){
				y[j].push(y[j-1][k]+dy[j]);
				if(dy[j] !== 0) y[j].push(y[j-1][k]-dy[j]);
			}
		}
	}

	if(xflg && yflg) console.log("Yes");
	else console.log("No");

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));