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 Julia (0.5.0) (judge verdict: Accepted)

parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	s = chomp(readline())
	x,y = readline() |> split |> parseMap
	h = Int[]
	v = Int[]
	f = 0
	c = 0
	for i in 1:length(s)
		if s[i] == 'T'
			if f == 0
				push!(h,c)
				f = 1
			else
				push!(v,c)
				f = 0
			end
			c = 0
		else
			c += 1
		end
	end
	if s[length(s)] == 'F'
		if f == 0
			push!(h,c)
		else
			push!(v,c)
		end
	end
	sh = sum(h)
	dph = zeros(Int,length(h), 2*sh+1)
	if length(h)>0
		dph[1,sh+1+h[1]] = 1
	end
	for i in 2:length(h)
		for j in 1:2*sh+1
			if j <= h[i]
				dph[i,j] = dph[i-1,j+h[i]]
			elseif j >= 2*sh+1-h[i]
				dph[i,j] = dph[i-1,j-h[i]]
			else
				dph[i,j] = max(dph[i-1,j+h[i]], dph[i-1,j-h[i]])
			end
		end
	end
	sv = sum(v)
	dpv = zeros(Int,length(v), 2*sv+1)
	if length(v)>0
		dpv[1,sv+1+v[1]] = 1
		dpv[1,sv+1-v[1]] = 1
	end
	for i in 2:length(v)
		for j in 1:2*sv+1
			if j <= v[i]
				dpv[i,j] = dpv[i-1,j+v[i]]
			elseif j >= 2*sv+1-v[i]
				dpv[i,j] = dpv[i-1,j-v[i]]
			else
				dpv[i,j] = max(dpv[i-1,j+v[i]], dpv[i-1,j-v[i]])
			end
		end
	end
	if sh+x+1<0||sh+x+1>2*sh+1||sv+y+1<0||sv+y+1>2*sv+1
		println("No")
	elseif length(h) == 0 && length(v) == 0
		println(x==0&&y==0?"Yes":"No")
	elseif length(h) == 0
		println(x==0&&dpv[length(v),sv+y+1]==1?"Yes":"No")
	elseif length(v) == 0
		println(dph[length(h),sh+x+1]==1&&y==0?"Yes":"No")
	else
		println(dph[length(h),sh+x+1]==1&&dpv[length(v),sv+y+1]==1?"Yes":"No")
	end
end
main()