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");
}


Measured memory_bytes: 12540