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: Time Limit Exceeded)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        s: Chars,
        x: isize,
        y: isize,
    }
    let n = s.len();
    let mut f_count = vec![0; n + 1];
    for i in (0..n).rev() {
        f_count[i] = f_count[i + 1];
        if s[i] == 'F' {
            f_count[i] += 1;
        }
    }

    let mut states0 = vec![];
    states0.push((0, 0, true, true));
    let mut states = vec![];
    let mut i = 0;
    while i < n {
        states.clear();
        if s[i] == 'F' {
            let mut c = 0;
            while i < n && s[i] == 'F' {
                c += 1;
                i += 1;
            }
            for &(xk, yk, horizontal, plus) in &states0 {
                let (dx, dy) = if horizontal {
                    if plus {
                        (c, 0)
                    } else {
                        (-c, 0)
                    }
                } else {
                    if plus {
                        (0, c)
                    } else {
                        (0, -c)
                    }
                };
                let new_x = xk + dx;
                let new_y = yk + dy;
                if (new_x - x).abs() + (new_y - y).abs() <= f_count[i] {
                    states.push((new_x, new_y, horizontal, plus));
                }
            }
        } else {
            for &(xk, yk, horizontal, _) in &states0 {
                states.push((xk, yk, !horizontal, true));
                states.push((xk, yk, !horizontal, false));
            }
            i += 1;
        }

        // eprintln!("{:?}", states);
        states0.clear();
        for &state in &states {
            states0.push(state);
        }
    }

    if states0.iter().any(|&(xk, yk, _, _)| xk == x && yk == y) {
        println!("Yes");
    } else {
        println!("No");
    }
}
*/

fn main() {
    let exe = "/tmp/binA40FE679";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";