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)

pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn abs(a: i32, b: i32) -> usize {
    if a > b {
        (a - b) as usize
    } else {
        (b - a) as usize
    }
}

fn main() {
    let s: String = read();
    let xy: Vec<i32> = read_vec();
    let x = xy[0];
    let y = xy[1];
    let cv: Vec<char> = s.chars().collect();

    let mut xvv: Vec<usize> = vec![];
    let mut yvv: Vec<usize> = vec![];

    let mut axisisx = true;
    let mut cnt = 0;
    for c in cv {
        if c == 'F' {
            cnt += 1;
        } else {
            if axisisx {
                xvv.push(cnt);
            } else {
                yvv.push(cnt);
            }
            cnt = 0;
            axisisx = !axisisx;
        }
    }
    if axisisx {
        xvv.push(cnt);
    } else {
        yvv.push(cnt);
    }

    xvv[0] = abs(xvv[0] as i32, x);
    yvv.push(abs(y, 0) as usize);

    let mut xv = vec![];
    let mut yv = vec![];
    let mut sumx = 0;
    let mut sumy = 0;
    let mut maxx = 0;
    let mut maxy = 0;
    for x in xvv {
        if x > 0 {
            xv.push(x);
            sumx += x;
            if x > maxx {
                maxx = x;
            }
        }
    }
    for y in yvv {
        if y > 0 {
            yv.push(y);
            sumy += y;
            if y > maxy {
                maxy = y;
            }
        }
    }

    if xv.len() != 0 {
        if sumx % 2 == 1 {
            println!("No");
            return;
        }
        let n = xv.len();
        let sum = sumx / 2;
        if maxx > sum {
            println!("No");
            return;
        }
        let mut map: Vec<Vec<bool>> = vec![vec![false; sum + 1]; n];
        map[0][xv[0]] = true;
        for i in 1..n {
            for j in 0..sum + 1 {
                if j < xv[i] {
                    map[i][j] = map[i - 1][j];
                } else {
                    map[i][j] = map[i - 1][j] || map[i - 1][j - xv[i]];
                }
            }
        }
        if !map[n - 1][sum] {
            println!("No");
            return;
        }
    }

    if yv.len() != 0 {
        if sumy % 2 == 1 {
            println!("No");
            return;
        }
        let n = yv.len();
        let sum = sumy / 2;
        if maxy > sum {
            println!("No");
            return;
        }
        let mut map: Vec<Vec<bool>> = vec![vec![false; sum + 1]; n];
        map[0][yv[0]] = true;
        for i in 1..n {
            for j in 0..sum + 1 {
                if j < yv[i] {
                    map[i][j] = map[i - 1][j];
                } else {
                    map[i][j] = map[i - 1][j] || map[i - 1][j - yv[i]];
                }
            }
        }
        if !map[n - 1][sum] {
            println!("No");
            return;
        }
    }

    println!("Yes");
}