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: Wrong Answer)

require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

s = gc
x,y = gi
tx,ty = 0,0
dir = 0

s.each do |ss|
  case ss
  when 'F'
    case dir
    when 0
      tx += 1
    when 1
      ty += 1
    when 2
      tx -= 1
    when 3
      ty -= 1
    end
  when 'T'
    case
    when dir == 0 && y - ty > 0
      dir = 1
    when dir == 0 && y - ty < 0
      dir = 3
    when dir == 0 && y - ty == 0
      dir = 1
    when dir == 1 && x - tx > 0
      dir = 0
    when dir == 1 && x - tx < 0
      dir = 2
    when dir == 1 && x - tx == 0
      dir = 0
    when dir == 2 && y - ty > 0
      dir = 1
    when dir == 2 && y - ty < 0
      dir = 3
    when dir == 2 && y - ty == 0
      dir = 1
    when dir == 3 && x - tx > 0
      dir = 0
    when dir == 3 && x - tx < 0
      dir = 2
    when dir == 3 && x - tx == 0
      dir = 0
    end
  end
end

puts tx == x && ty == y ? 'Yes' : 'No'