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)

use std::io::stdin;
use std::str::FromStr;

fn main(){
    let s = get_chars();
    let (x, y): (i64, i64) = get_pair();
    let fs = as_fs(&s);
    let bias = 8499;
    let range = 17000;
    let mut xs_after = vec![false; range];
    let mut ys_after = vec![false; range];
    let mut xs_before;
    let mut ys_before;
    xs_after[bias + fs[0] as usize] = true;
    ys_after[bias] = true;
    for i in 1..fs.len() {
        if i % 2 == 0 {
            xs_before = xs_after;
            xs_after = vec![false; range];
            for j in 0..range {
                if xs_before[j] {
                    xs_after[(j as i64 - fs[i]) as usize] = true;
                    xs_after[(j as i64 + fs[i]) as usize] = true;
                }
            }
        } else {
            ys_before = ys_after;
            ys_after = vec![false; range];
            for j in 0..range {
                if ys_before[j] {
                    ys_after[(j as i64 - fs[i]) as usize] = true;
                    ys_after[(j as i64 + fs[i]) as usize] = true;
                }
            }
        }
    }
    if xs_after[(bias as i64 +x) as usize] && ys_after[(bias as i64 +y) as usize] {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn as_fs(s: &Vec<char>) -> Vec<i64> {
    let mut fs = Vec::new();
    let mut j = 0;
    for &c in s {
        if c == 'T' {
            fs.push(j);
            j =  0;
        } else {
            j += 1;
        }
    }
    fs.push(j);

    fs
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}