Language: Go

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

const (
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {

	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	S    []rune
	x, y int

	dpx, dpy [8000][20000]bool
)

func main() {
	S = ReadRuneSlice()
	x, y = ReadInt2()

	F := []int{}

	cur := 0
	for i := 0; i < len(S); i++ {
		if S[i] == 'F' {
			cur++
		} else {
			F = append(F, cur)
			cur = 0
		}
	}
	F = append(F, cur)
	PrintfDebug("%v\n", F)

	evens, odds := []int{}, []int{}
	for i := 0; i < len(F); i++ {
		if i%2 == 0 {
			evens = append(evens, F[i])
		} else {
			odds = append(odds, F[i])
		}
	}

	dpx[0][10000], dpy[0][10000] = true, true
	for i := 0; i < len(evens); i++ {
		val := evens[i]
		for j := 2000; j <= 18000; j++ {
			if j+val <= 18000 {
				dpx[i+1][j+val] = dpx[i+1][j+val] || dpx[i][j]
			}
			if j-val >= 2000 && i != 0 {
				dpx[i+1][j-val] = dpx[i+1][j-val] || dpx[i][j]
			}
		}
	}
	for i := 0; i < len(odds); i++ {
		val := odds[i]
		for j := 2000; j <= 18000; j++ {
			if j+val <= 18000 {
				dpy[i+1][j+val] = dpy[i+1][j+val] || dpy[i][j]
			}
			if j-val >= 2000 {
				dpy[i+1][j-val] = dpy[i+1][j-val] || dpy[i][j]
			}
		}
	}

	if dpx[len(evens)][x+10000] && dpy[len(odds)][y+10000] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var (
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9))
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10)
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}


Example test case(s):
input: FTFFTFFF
4 2

output: Yes