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)

// 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::*;

fn main() {
    input! {
        s: Bytes,
        mut x: i64, y: i64,
    }
    let mut v = kyopro_lib::rle::RLE::new();
    for s in s {
        v.push(s);
    }
    let mut x_s = std::collections::BTreeSet::new();
    let mut y_s = std::collections::BTreeSet::new();
    x_s.insert(0);
    y_s.insert(0);
    let mut d = true; // t:x, f: y
    let mut f = true;
    for &(c, n) in v.v() {
        if c == b'T' {
            if n % 2 == 1 {
                d = !d;
            }
            f = false;
        } else {
            if f {
                x -= n as i64;
                f = false;
            } else if d {
                let mut s = std::collections::BTreeSet::new();
                for x in x_s {
                    s.insert(x + n as i64);
                    s.insert(x - n as i64);
                }
                x_s = s;
            } else {
                let mut s = std::collections::BTreeSet::new();
                for y in y_s {
                    s.insert(y + n as i64);
                    s.insert(y - n as i64);
                }
                y_s = s;
            }
        }
    }
    // println!("{} {}", x, y);
    // println!("{:?}", x_s);
    // println!("{:?}", y_s);
    if x_s.contains(&x) && y_s.contains(&y) {
        println!("Yes");
    } else {
        println!("No");
    }
}
*/

fn main() {
    let exe = "/tmp/binDAA3474D";
    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>";