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: Accepted)

#[allow(dead_code)]
fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

#[allow(unused_macros)]
macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}
// macro_rules! debug { ($x: expr) => () }

#[allow(dead_code)]
fn show<T>(iter: T) -> String
where
    T: Iterator,
    T::Item: std::fmt::Display
{
    let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e));
    res.pop();
    res
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }
    let s = readl!(String);
    let (x, y) = readl!(i32, i32);
    let dx = [-1, 0, 1, 0];
    let dy = [0, -1, 0, 1];
    let mut cxy = [0, 0];
    let mut ii = 0;
    let m = s.len()*2+3;
    let mut dp = [vec![[false, false]; m*2], vec![[false, false]; m*2]];
    // let c =  s.chars().take_while(|&x| x == 'F').count();
    // dp[0].insert(c as i32);
    // dp[1].insert(0);
    dp[0][m+0] = [true, false];
    dp[1][m+0] = [true, true];
    for c in s.chars() {
        // debug!(dp[00]);
        // debug!(dp[01]);
        if c == 'T' {
            ii = 1-ii;
            for e in &mut dp[ii] {
                if e[0] || e[1] {
                    e[0] = true;
                    e[1] = true;
                }
            }
        } else {
            let mut nex = vec![[false, false]; m*2];
            for i in 1..dp[ii].len()-1 {
                if dp[ii][i][0] {
                    nex[i+1][0] = true;
                }
            }
            for i in 1..dp[ii].len()-1 {
                if dp[ii][i][1] {
                    nex[i-1][1] = true;
                }
            }
            dp[ii] = nex;
        }
    }
    if (dp[0][(m as i32+x) as usize][0] || dp[0][(m as i32+x) as usize][1]) 
        && (dp[1][(m as i32+y) as usize][0] || dp[1][(m as i32+y) as usize][1]) {
        println!("Yes");
    } else {
        println!("No");
    }
}