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 Ruby (2.3.3) (judge verdict: Time Limit Exceeded)

s = gets.chomp.split("")
x,y = gets.split(" ").map(&:to_i)

op = []
s.each do |method|
  if op.empty?
    op << [method,1]
  else
    if op.last[0] == method
      op.last[1] += 1
    else
      op << [method,1]
    end
  end
end

arr = [{c:[0,0],lr:1,ud:0}]

op.each do |method|
#  puts "m: #{method}"
  if method[0] == "F"
    arr.each do |a|
#      p a
      a[:c][0] += a[:lr] * method[1]
      a[:c][1] += a[:ud] * method[1]
#      p a
    end
  else
    arr2 = []
    if method[1].even?
      arr.each do |a|
        lr = a[:lr]
        ud = a[:ud]
        c = a[:c]
#        arr2 << a.clone#{c:c,lr:lr,ud:ud}
        if lr != 0
          lr *= -1
        end
        if ud != 0
          ud *= -1
        end
        arr2 << {c:c.clone,lr:lr,ud:ud}
      end
    else
      arr.each do |a|
        lr = a[:lr]
        ud = a[:ud]
        c = a[:c]
        if lr == 0
          a[:lr] = 1
          a[:ud] = 0
          #arr2 << {c:c.clone,lr:1,ud:0}
          arr2 << {c:c.clone,lr:-1,ud:0}
        end
        if ud == 0
          a[:lr] = 0
          a[:ud] = 1
#          arr2 << {c:c.clone,lr:0,ud:1}
          arr2 << {c:c.clone,lr:0,ud:-1}
        end
      end
    end
    arr += arr2
  end
end

if arr.any?{|a| a[:c] == [x,y]}
  puts "Yes"
  exit
end
puts "No"

exit