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 Rust (1.15.1) (judge verdict: Runtime Error)

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

use std::rc::Rc;
use std::cell::RefCell;
use std::collections::HashMap;

fn _solve(goal: i32, ins: &Vec<i32>, start: i32) -> bool {
    if ins.is_empty() { return goal == start }

    let total = ins.iter().fold(0, |sum, a| sum+a);

    let mut dp = vec![vec![false; (total*2+1) as usize];ins.len()];
    let dist = ins[0];
    dp[0][(total+dist) as usize] = true;
    dp[0][(total-dist) as usize] = true;

    for i in 1..ins.len() {
        for j in 0..(total*2+1) {
            let dist = ins[i];
            let from_left = if j < dist {
                false
            } else {
                dp[(i-1) as usize][(j-dist) as usize]
            };

            let from_right = if j+dist > 2*total {
                false
            } else {
                dp[(i-1) as usize][(j+dist) as usize]
            };

            dp[i as usize][j as usize] = from_left || from_right
        }
    }

    dp[ins.len()-1][(goal - start + total) as usize]
}


fn solve(x:i32, y:i32, s: Vec<char>) -> bool {
    let mut ins = vec![Vec::new(), Vec::new()];
    let mut dir = 0;

    let mut cnt = 0;
    for c in s.iter() {
        if *c == 'F' {
            cnt += 1;
        } else {
            ins[dir].push(cnt);
            cnt = 0;
            dir ^= 1;
        }
    }
    ins[dir].push(cnt);

    let mut xstart = 0;

    if s[0] == 'F' {
        xstart = ins[0].remove(0);
    }

//    println!("{} {} {:?} {:?} {}", x,y,ins[0], ins[1], xstart);

    _solve(x, &ins[0].iter().cloned().filter(|&n| n != 0).collect(), xstart) &&
        _solve(y, &ins[1].iter().cloned().filter(|&n| n != 0).collect(), 0)

}

fn main() {
    let s = read_line!();
    let (x, y) = parse_line!(i32, i32);

    println!("{}", if solve(x, y, s.chars().collect()) {"Yes"} else {"No"});
}

#[test]
fn _solve_test() {
    assert_eq!(_solve(2, &vec![1], 1), true);
    assert_eq!(_solve(2, &vec![1], 2), false);

    assert_eq!(_solve(2, &vec![1,1], 0), true);
    assert_eq!(_solve(0, &vec![1,1], 0), true);


    assert_eq!(solve(4,2, "FTFFTFFF".chars().collect()), true);
    assert_eq!(solve(-2, -2, "FTFFTFFF".chars().collect()), true);
    assert_eq!(solve(1,0, "FF".chars().collect()), false);
    assert_eq!(solve(1,0, "TF".chars().collect()), false);
}