AtCoder Regular Contest 087 - FT Robot

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-----
FTFFTFFF
4 2

-----Sample Output-----
Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T.

Difficulty: HARD

Starter code:

Solutions:
s = input().split('T')
(gx, gy) = map(int, input().split())
for (i, e) in enumerate(s):
	s[i] = len(e)
(xs, ys) = (s[::2], s[1::2])
x = xs.pop(0) if len(xs) > 0 else 0
y = 0
xs.sort(reverse=True)
ys.sort(reverse=True)

def c(p, g, lis):
	for e in lis:
		if p <= g:
			p += e
		else:
			p -= e
	return p == g
if c(x, gx, xs) and c(y, gy, ys):
	print('Yes')
else:
	print('No')


s = input().split('T')
(x, y) = map(int, input().split())
x -= len(s[0])
s.pop(0)
list_yoko = [len(s[i]) for i in range(1, len(s), 2)]
list_tate = [len(s[i]) for i in range(0, len(s), 2)]
if list_yoko == []:
	list_yoko = [0]
if list_tate == []:
	list_tate = [0]
set_yoko = {list_yoko[0], -list_yoko[0]}
set_tate = {list_tate[0], -list_tate[0]}
for i in list_yoko[1:]:
	sy = set()
	for j in set_yoko:
		sy |= {j + i, j - i}
	set_yoko = sy
for i in list_tate[1:]:
	st = set()
	for j in set_tate:
		st |= {j + i, j - i}
	set_tate = st
if x in set_yoko and y in set_tate:
	print('Yes')
else:
	print('No')


s = list(input())
(x, y) = map(int, input().split())
z = [0]
for i in s:
	if i == 'F':
		z[-1] += 1
	else:
		z.append(0)
_y = len(z) // 2
_x = len(z) - _y
len_s = len(s)
dp_x = [0 for _i in range(2 * len_s + 2)]
dp_x_to = [0 for _i in range(2 * len_s + 2)]
dp_y = [0 for _i in range(2 * len_s + 2)]
dp_y_to = [0 for _i in range(2 * len_s + 2)]
dp_x[z[0]] = 1
dp_y[0] = 1
for i in range(1, len(z)):
	if i % 2 == 0:
		for j in range(-len_s, len_s + 1):
			dp_x_to[j] = max(dp_x[j - z[i]], dp_x[j + z[i]])
		dp_x = dp_x_to.copy()
	else:
		for j in range(-len_s, len_s + 1):
			dp_y_to[j] = max(dp_y[j - z[i]], dp_y[j + z[i]])
		dp_y = dp_y_to.copy()
if dp_x[x] == dp_y[y] == 1:
	print('Yes')
else:
	print('No')


import copy
s = input()
(X, Y) = list(map(int, input().split()))
s += 'T'
now = 1
start = 0
go = 0
x = []
y = []
for i in s:
	if i == 'T':
		if start == 0:
			X = X - go
			go = 0
			start = 1
		elif go != 0:
			if now == 1:
				x.append(go)
			else:
				y.append(go)
			go = 0
		now *= -1
	if i == 'F':
		go += 1
x.sort()
y.sort()
x = x[::-1]
y = y[::-1]
X = abs(X)
Y = abs(Y)
x_use = sum(x) - X
y_use = sum(y) - Y
if x_use % 2 == 1 or y_use % 2 == 1 or x_use < 0 or (y_use < 0):
	print('No')
	exit()
x_use = x_use // 2
y_use = y_use // 2

def solve(integer_list, target_sum, i=0, sum=0):
	if sum > target_sum:
		return False
	if sum == target_sum:
		return True
	if i == len(integer_list):
		return sum == target_sum
	if solve(integer_list, target_sum, i + 1, sum):
		return True
	if solve(integer_list, target_sum, i + 1, sum + integer_list[i]):
		return True
	return False

def part_sum0(a, A):
	N = len(a)
	dp = [[0 for i in range(A + 1)] for j in range(N + 1)]
	dp[0][0] = 1
	for i in range(N):
		for j in range(A + 1):
			if a[i] <= j:
				dp[i + 1][j] = dp[i][j - a[i]] or dp[i][j]
			else:
				dp[i + 1][j] = dp[i][j]
	return dp[N][A]
if part_sum0(x, x_use) and part_sum0(y, y_use):
	print('Yes')
else:
	print('No')


import sys
s = input()
(x, y) = map(int, input().split())
s = s + 'T'
dp = [[] for i in range(2)]
t = 0
buf = 0
for j in range(len(s)):
	if s[j] == 'T':
		break
for i in range(j, len(s)):
	if s[i] == 'F':
		buf += 1
	else:
		if buf != 0:
			dp[t].append(buf)
			buf = 0
		t = 1 - t
xb = 1 << len(s) + j
yb = 1 << len(s)
for i in range(len(dp[0])):
	xb = xb << dp[0][i] | xb >> dp[0][i]
if xb & 1 << len(s) + x == 0:
	print('No')
	sys.exit()
for i in range(len(dp[1])):
	yb = yb << dp[1][i] | yb >> dp[1][i]
if yb & 1 << len(s) + y == 0:
	print('No')
	sys.exit()
print('Yes')


s = input()
(x, y) = map(int, input().split())
flg = 1
x_list = []
y_list = []
tmp = 0
for (i, si) in enumerate(s):
	if si == 'F':
		tmp += 1
	else:
		if flg == 1:
			x_list.append(tmp)
		else:
			y_list.append(tmp)
		flg *= -1
		tmp = 0
if flg == 1:
	x_list.append(tmp)
else:
	y_list.append(tmp)
x = sum(x_list) - x
y = sum(y_list) - y
if x % 2 != 0 or y % 2 != 0:
	print('No')
	exit()
if x < 0 or y < 0:
	print('No')
	exit()
x //= 2
y //= 2
if s[0] == 'F':
	x_list.reverse()
	x_list.pop()
dpx = [[0] * (x + 1) for _ in range(len(x_list) + 1)]
dpx[0][0] = 1
dpy = [[0] * (y + 1) for _ in range(len(y_list) + 1)]
dpy[0][0] = 1
for i in range(len(x_list)):
	for j in range(x + 1):
		if dpx[i][j]:
			dpx[i + 1][j] = 1
			if j + x_list[i] <= x:
				dpx[i + 1][j + x_list[i]] = 1
for i in range(len(y_list)):
	for j in range(y + 1):
		if dpy[i][j]:
			dpy[i + 1][j] = 1
			if j + y_list[i] <= y:
				dpy[i + 1][j + y_list[i]] = 1
if dpx[-1][-1] and dpy[-1][-1]:
	print('Yes')
else:
	print('No')


s = input().rstrip()
s += 'T'
(x, y) = map(int, input().split())
cnt = 0
dir = 0
P = [{0}, {0}]
first = True
for i in range(len(s)):
	if s[i] == 'F':
		cnt += 1
	else:
		tmp = set()
		if first:
			for p in P[dir % 2]:
				tmp |= {p + cnt}
			first = False
		else:
			for p in P[dir % 2]:
				tmp |= {p + cnt, p - cnt}
		P[dir % 2] = tmp
		dir += 1
		cnt = 0
if x in P[0] and y in P[1]:
	print('Yes')
else:
	print('No')


from collections import Counter
from itertools import product

def inpl():
	return tuple(map(int, input().split()))
S = input()
(x, y) = inpl()
M = []
d = 0
for s in S:
	if s == 'F':
		d += 1
	else:
		M.append(d)
		d = 0
M.append(d)
Cx = Counter(M[2::2])
Cy = Counter(M[1::2])
Lx = []
Ly = []
for (k, v) in Cx.items():
	if k == 0:
		pass
	else:
		Lx.append(list(range(-k * v, k * v + 1, 2 * k)))
for (k, v) in Cy.items():
	if k == 0:
		pass
	else:
		Ly.append(list(range(-k * v, k * v + 1, 2 * k)))

def bfss(Ls, t, f):
	N = set([f])
	for L in Ls:
		nN = set([n + l for (n, l) in product(N, L)])
		N = nN
	if t in N:
		return True
	else:
		return False
if bfss(Lx, x, M[0]) and bfss(Ly, y, 0):
	print('Yes')
else:
	print('No')


s = input()
(x, y) = list(map(int, input().split()))
C = [len(fs) for fs in s.split('T')]

def f(cs, t):
	dp = {0}
	for c in cs:
		dp = {i + c for i in dp} | {i - c for i in dp}
	return t in dp
ans = 'Yes' if f(C[2::2], x - C[0]) and f(C[1::2], y) else 'No'
print(ans)


from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

def solve():
	S = input()[:-1]
	(GX, GY) = list(map(int, input().split()))
	S_parsed = []
	prev = S[0]
	seq = 1
	for c in S[1:]:
		if c == 'F':
			if c == prev:
				seq += 1
			else:
				prev = c
				if seq % 2 == 0:
					pass
				else:
					S_parsed.append('T')
				seq = 1
		elif c == 'T':
			if c == prev:
				seq += 1
			else:
				S_parsed.append(seq)
				seq = 1
			prev = c
	else:
		if S[-1] == 'F':
			S_parsed.append(seq)
	x_move = []
	y_move = []
	dir_x = True
	for c in S_parsed:
		if c == 'T':
			dir_x = not dir_x
		elif dir_x:
			x_move.append(c)
		else:
			y_move.append(c)
	dp_x = set()
	if len(x_move) > 0:
		if S[0] != 'T':
			dp_x.add(x_move[0])
		else:
			dp_x.add(x_move[0])
			dp_x.add(-x_move[0])
	else:
		dp_x.add(0)
	for x in x_move[1:]:
		dp_x = {key + x for key in dp_x} | {key - x for key in dp_x}
	dp_y = set()
	if len(y_move) == 0:
		dp_y.add(0)
	else:
		dp_y.add(y_move[0])
		dp_y.add(-y_move[0])
	for y in y_move[1:]:
		dp_y = {key + y for key in dp_y} | {key - y for key in dp_y}
	if GX in dp_x and GY in dp_y:
		print('Yes')
	else:
		print('No')
solve()


from collections import defaultdict as dd
s = input().strip()
n = len(s)
(x, y) = list(map(int, input().strip().split()))
stx = 0
while stx < n and s[stx] == 'F':
	stx += 1
sty = 0
(X, Y) = list(range(2))
x_blocks = []
y_blocks = []
curr = 0
cdi = X
for i in range(stx, n):
	ch = s[i]
	if ch == 'F':
		curr += 1
	else:
		if curr != 0:
			if cdi == X:
				x_blocks.append(curr)
			else:
				y_blocks.append(curr)
		curr = 0
		cdi = (cdi + 1) % 2
if curr != 0:
	if cdi == X:
		x_blocks.append(curr)
	else:
		y_blocks.append(curr)
curr = dd(int)
curr[stx] = 1
for xb in x_blocks:
	nxt = dd(int)
	for key in curr.keys():
		nxt[key + xb] += 1
		nxt[key - xb] += 1
	curr = nxt
if x not in curr:
	print('No')
	return
curr = dd(int)
curr[sty] = 1
for yb in y_blocks:
	nxt = dd(int)
	for key in curr.keys():
		nxt[key + yb] += 1
		nxt[key - yb] += 1
	curr = nxt
if y not in curr:
	print('No')
else:
	print('Yes')


def search(arr, start):
	s = set()
	s.add(start)
	for i in arr:
		ns = set()
		for j in s:
			ns.add(j + i)
			ns.add(j - i)
		s = ns
	return s

def main():
	t = 0
	(xd, yd) = ([], [])
	inst = list(input())
	(x, y) = list(map(int, input().split()))
	xcum = 0
	ycum = 0
	first = True
	startx = 0
	for s in inst:
		if s == 'T':
			t += 1
			t %= 2
			if first:
				startx = xcum
				xcum = 0
				first = False
				continue
			if xcum > 0:
				xd.append(xcum)
				xcum = 0
			if ycum > 0:
				yd.append(ycum)
				ycum = 0
		elif t == 0:
			xcum += 1
		else:
			ycum += 1
	if first:
		startx = xcum
	elif xcum > 0:
		xd.append(xcum)
		xcum = 0
	if ycum > 0:
		yd.append(ycum)
		ycum = 0
	if x in search(xd, startx) and y in search(yd, 0):
		print('Yes')
	else:
		print('No')

def __starting_point():
	main()
__starting_point()


def main():
	s = input()
	(x, y) = map(int, input().split())
	n = len(s)
	(x1, y1) = (0, 0)
	i = 0
	while i < n and s[i] == 'F':
		x1 += 1
		i += 1
	count = 0
	UD = []
	LR = []
	while i < n:
		if s[i] == 'T':
			count += 1
			i += 1
		else:
			d = 0
			while i < n and s[i] == 'F':
				d += 1
				i += 1
			if count % 2 == 1:
				UD.append(d)
			else:
				LR.append(d)
	s1 = set([x1])
	for v in LR:
		temp = set()
		for u in s1:
			temp.add(u + v)
			temp.add(u - v)
		s1 = temp
	if x not in s1:
		return 'No'
	s2 = set([0])
	for v in UD:
		temp = set()
		for u in s2:
			temp.add(u + v)
			temp.add(u - v)
		s2 = temp
	if y not in s2:
		return 'No'
	return 'Yes'
print(main())


S = str(input())
s = list(S)
(x, y) = map(int, input().split())
fora = 0
side = []
updw = []
while s[0] == 'F':
	fora += 1
	s.pop(0)
	if len(s) == 0:
		break
flag = 1
step = 0
while s:
	if s[0] == 'T':
		s.pop(0)
		if step:
			if flag == -1:
				updw += [step]
			else:
				side += [step]
		flag = flag * -1
		step = 0
	else:
		s.pop(0)
		step += 1
		if len(s) == 0:
			if flag == -1:
				updw += [step]
			else:
				side += [step]
ypossi = len(side)
tpossi = len(updw)
X = sum(side) + fora + abs(x)
Y = sum(updw) + abs(y)
xdp = [[0 for i in range(2 * X + 1)] for j in range(ypossi + 1)]
xdp[0][fora + X] = 1
for i in range(ypossi):
	for j in range(2 * X + 1):
		if j - side[i] >= 0:
			if xdp[i][j - side[i]] == 1:
				xdp[i + 1][j] = 1
		if j + side[i] < 2 * X + 1:
			if xdp[i][j + side[i]] == 1:
				xdp[i + 1][j] = 1
ydp = [[0 for i in range(2 * Y + 1)] for j in range(tpossi + 1)]
ydp[0][Y] = 1
for i in range(tpossi):
	for j in range(2 * Y + 1):
		if j - updw[i] >= 0:
			if ydp[i][j - updw[i]] == 1:
				ydp[i + 1][j] = 1
		if j + updw[i] < 2 * Y + 1:
			if ydp[i][j + updw[i]] == 1:
				ydp[i + 1][j] = 1
if xdp[ypossi][x + X] == 1 and ydp[tpossi][y + Y] == 1:
	print('Yes')
else:
	print('No')


s = [len(x) for x in input().split('T')]
(x, y) = map(int, input().split())
len_s = len(s)
sx = [s[i] for i in range(len_s) if i % 2 == 0]
sy = [s[i] for i in range(len_s) if i % 2 == 1]
x -= sx[0]
sx = sx[1:]

def is_reachable(p, s):
	origin = 8000
	if origin + p < 0:
		return False
	n = len(s)
	reachable = [set() for i in range(n + 1)]
	reachable[0].add(origin)
	for i in range(n):
		for j in list(reachable[i]):
			if j - s[i] >= 0:
				reachable[i + 1].add(j - s[i])
			if j + s[i] <= origin * 2:
				reachable[i + 1].add(j + s[i])
	return origin + p in reachable[n] or origin - p in reachable[n]
if is_reachable(x, sx) and is_reachable(y, sy):
	print('Yes')
else:
	print('No')


s = input()
(x, y) = map(int, input().split())
s2 = s.split('T')
sXs = list(map(len, s2[0::2]))
sYs = list(map(len, s2[1::2]))
memoX = [{sXs[0]}, set()]
for (i, sX) in enumerate(sXs[1:]):
	memoX[1 - i % 2] = set()
	for p in memoX[i % 2]:
		memoX[1 - i % 2].add(p + sX)
		memoX[1 - i % 2].add(p - sX)
memoY = [{0}, set()]
for (i, sY) in enumerate(sYs):
	memoY[1 - i % 2] = set()
	for p in memoY[i % 2]:
		memoY[1 - i % 2].add(p + sY)
		memoY[1 - i % 2].add(p - sY)
if x in memoX[1 - len(sXs) % 2] and y in memoY[len(sYs) % 2]:
	print('Yes')
else:
	print('No')


ma = lambda : map(int, input().split())
lma = lambda : list(map(int, input().split()))
tma = lambda : tuple(map(int, input().split()))
ni = lambda : int(input())
yn = lambda fl: print('Yes') if fl else print('No')
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil
FT = []
s = input()
(x, y) = ma()
if s[0] == 'T':
	FT.append(0)
prev = s[0]
cnt = 0
for i in range(len(s)):
	if s[i] == prev:
		cnt += 1
	else:
		FT.append(cnt)
		cnt = 1
	prev = s[i]
FT.append(cnt)
Fxy = [[], []]
idx = 0
for i in range(len(FT)):
	if i % 2 == 0:
		Fxy[idx].append(FT[i])
	elif FT[i] % 2 == 0:
		pass
	else:
		idx = (idx + 1) % 2

def reach(xls, x, f=False):
	l = len(xls)
	su = sum(xls)
	if abs(x) > su:
		return False
	dp = [[False] * (2 * su + 1) for _ in range(l + 1)]
	dp[0][0] = True
	for i in range(l):
		d = xls[i]
		if i == 0 and f:
			if s[0] == 'F':
				dp[1][d] = True
				continue
		for j in range(-su, su + 1):
			dp[i + 1][j] = dp[i][j - d] or dp[i][j + d]
	return dp[-1][x]
fx = reach(Fxy[0], x, f=True)
fy = reach(Fxy[1], y)
yn(fx and fy)


from sys import setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import *

def read():
	return int(input())

def reads():
	return [int(x) for x in input().split()]
S = input()
(x, y) = reads()
qs = [len(s) for s in S.split('T')]

def knapsack(xs, target):
	es = {0}
	for x in xs:
		es = {e - x for e in es} | {e + x for e in es}
	return target in es
ans = knapsack(qs[2::2], x - qs[0]) and knapsack(qs[1::2], y)
print('Yes' if ans else 'No')


def solve(s, x, y):

	def update(move):
		ncx = set()
		cx = cxy[is_x]
		for x in cx:
			ncx.add(x + move)
			ncx.add(x - move)
		cxy[is_x] = ncx
	spl = map(len, s.split('T'))
	is_x = 1
	cxy = [{next(spl)}, {0}]
	for l in spl:
		update(l)
		is_x ^= 1
	return x in cxy[0] and y in cxy[1]
s = input()
(x, y) = map(int, input().split())
print('Yes' if solve(s, x, y) else 'No')


s = input()
(x, y) = map(int, input().split())
m = list(map(len, s.split('T')))
dp_x = {m[0]}
for i in m[2::2]:
	new_dp = set()
	for v in dp_x:
		new_dp |= {v + i, v - i}
	dp_x = new_dp
dp_y = {0}
for i in m[1::2]:
	new_dp = set()
	for v in dp_y:
		new_dp |= {v + i, v - i}
	dp_y = new_dp
print('Yes' if x in dp_x and y in dp_y else 'No')


def solve(s, x, y):
	first_t = s.find('T')
	if first_t == -1:
		return x == len(s) and y == 0

	def update(move):
		ncx = set()
		cx = cxy[is_x]
		for x in cx:
			ncx.add(x + move)
			ncx.add(x - move)
		cxy[is_x] = ncx
	is_x = 1
	prev = first_t
	cxy = [{first_t}, {0}]
	for (i, c) in list(enumerate(s))[first_t + 1:]:
		if c == 'T':
			move = i - prev - 1
			update(move)
			is_x ^= 1
			prev = i
	update(len(s) - prev - 1)
	return x in cxy[0] and y in cxy[1]
s = input()
(x, y) = map(int, input().split())
print('Yes' if solve(s, x, y) else 'No')


import sys
sys.setrecursionlimit(8001)
s = input()
(X, Y) = map(int, input().split())
S = list(map(len, s.split('T')))
N = len(S)
x = S[0]
y = 0
xmoves = S[2::2]
xmoves.sort()
xmoves.reverse()
ymoves = S[1::2]
ymoves.sort()
ymoves.reverse()

def process(a, l, i, v, d, memo, r):
	if (i, v) in memo:
		return False
	if l == i:
		return v == d
	ab = abs(d - v)
	if ab > r:
		ret = False
	elif a == r:
		ret = True
	else:
		ret = process(a, l, i + 1, v + a[i], d, memo, r - a[i]) or process(a, l, i + 1, v - a[i], d, memo, r - a[i])
	memo[i, v] = ret
	return ret
if process(xmoves, len(xmoves), 0, x, X, {}, sum(xmoves)) and process(ymoves, len(ymoves), 0, y, Y, {}, sum(ymoves)):
	print('Yes')
else:
	print('No')


def f(m, l):
	tmpm = set()
	for x in m:
		tmpm.add(x + l)
		tmpm.add(x - l)
	return tmpm
s = input() + 'T'
(x, y) = map(int, input().split())
while s and s[0] == 'F':
	x -= 1
	s = s[1:]
ss = [{0}, {0}]
mode = 0
l = 0
for i in range(len(s)):
	if s[i] == 'F':
		l += 1
	else:
		ss[mode] = f(ss[mode], l)
		mode ^= 1
		l = 0
print('Yes' if x in ss[0] and y in ss[1] else 'No')


from functools import reduce
s = input()
(x, y) = map(int, input().split())
C = [len(fs) for fs in s.split('T')]

def f(cs, t):
	return t in reduce(lambda acc, c: {i + c for i in acc} | {i - c for i in acc}, cs, {0})
ans = 'Yes' if f(C[2::2], x - C[0]) and f(C[1::2], y) else 'No'
print(ans)


import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float('inf')
sys.setrecursionlimit(10 ** 7)
(dy4, dx4) = ([0, -1, 0, 1], [1, 0, -1, 0])

def inside(y: int, x: int, H: int, W: int) -> bool:
	return 0 <= y < H and 0 <= x < W

def ceil(a, b):
	return (a + b - 1) // b
YES = 'Yes'
NO = 'No'

def check(x, nums):
	x = abs(x)
	dp = [False] * (x + 1)
	dp[0] = True
	for y in nums:
		tmp = [False] * (x + 1)
		for i in range(len(dp)):
			if i + y < len(tmp):
				tmp[i + y] |= dp[i]
			if i - y >= 0:
				tmp[i - y] |= dp[i]
		dp = tmp
	return dp[x]

def solve(s, x, y):
	type_num = [(k, len(list(g))) for (k, g) in groupby(s)]
	if s[0] == 'F':
		x -= type_num[0][1]
		type_num.pop(0)
	(h, v) = ([], [])
	now = 0
	for (t, n) in type_num:
		if t == 'F':
			if now == 0:
				h.append(n)
			else:
				v.append(n)
		elif n % 2 != 0:
			now = (now + 1) % 2
	return YES if check(x, h) and check(y, v) else NO

def main():
	s = input()
	(x, y) = map(int, input().split())
	print(solve(s, x, y))
main()


s = input().split('T')
(x, y) = map(int, input().split())
xmove = []
ymove = []
for i in range(len(s)):
	if i % 2 == 1:
		ymove.append(s[i].count('F'))
	else:
		xmove.append(s[i].count('F'))

def solve(l, cor):
	dp = {0}
	for c in l:
		dp = {c + i for i in dp} | {i - c for i in dp}
	return cor in dp
if solve(xmove[1:], x - xmove[0]) and solve(ymove, y):
	print('Yes')
else:
	print('No')


def c(p, g, lis):
	for e in lis:
		if p <= g:
			p += e
		else:
			p -= e
	return p == g
s = input()
(gx, gy) = map(int, input().split())
s = s.split('T')
s = [len(_) for _ in s]
x_move = s[::2]
y_move = s[1::2]
x = x_move.pop(0)
y = 0
x_move.sort(reverse=True)
y_move.sort(reverse=True)
if c(x, gx, x_move) and c(y, gy, y_move):
	print('Yes')
else:
	print('No')


s = input()
(x, y) = map(int, input().split())
FT_1 = [0]
FT_2 = [0]
state = 1
for a in s:
	if a == 'T':
		if state == 1:
			state = 2
			FT_2.append(0)
		else:
			state = 1
			FT_1.append(0)
	elif state == 1:
		FT_1[-1] += 1
	else:
		FT_2[-1] += 1
DP_1 = 1
x -= FT_1[0]
x -= -sum(FT_1[1:])
DP_2 = 1
y -= FT_2[0]
y -= -sum(FT_2[1:])
for v in FT_1[1:]:
	DP_1 |= DP_1 << 2 * v
for v in FT_2[1:]:
	DP_2 |= DP_2 << 2 * v
if x >= 0 and y >= 0 and DP_1 >> x & 1 and DP_2 >> y & 1:
	print('Yes')
else:
	print('No')


s = input() + 'T'
(x, y) = [int(i) for i in input().split()]
dire = True
xi = []
yi = []
ctr = 0
for i in range(len(s)):
	if s[i] == 'F':
		ctr += 1
		continue
	if dire:
		xi.append(ctr)
	else:
		yi.append(ctr)
	ctr = 0
	dire = not dire
ans = 'Yes'
X = (sum(xi) - x) // 2
x0 = xi.pop(0)
Hx = {0: True}
for i in xi:
	for j in Hx.copy().keys():
		Hx[j + i] = True
Y = (sum(yi) - y) // 2
Hy = {0: True}
for i in yi:
	for j in Hy.copy().keys():
		Hy[j + i] = True
if (x0 + sum(xi) - x) % 2 != 0 or (sum(yi) - y) % 2 != 0:
	ans = 'No'
if not Hx.get(X, False) or not Hy.get(Y, False):
	ans = 'No'
print(ans)


s = input()
(x, y) = map(int, input().split())
tInd = [i for (i, x) in enumerate(s) if x == 'T']
xs = []
ys = [0]
answer = 'No'
xa = False
firstT = False
if s[0] == 'T':
	firstT = True
start = 0
isx = 1
for i in tInd:
	if isx == 1:
		xs.append(i - start)
	else:
		ys.append(i - start)
	isx *= -1
	start = i + 1
if isx == 1:
	xs.append(len(s) - start)
else:
	ys.append(len(s) - start)
cset = {0}
for (index, item) in enumerate(xs):
	tcset = set()
	if index == 0 and (not firstT):
		tcset.add(item)
	else:
		for c in cset:
			tcset.add(c + item)
			tcset.add(c - item)
	cset = tcset
if x in cset:
	xa = True
if xa:
	cset = {0}
	for item in ys:
		tcset = set()
		for c in cset:
			tcset.add(c + item)
			tcset.add(c - item)
		cset = tcset
	if y in cset:
		answer = 'Yes'
print(answer)


(*s,) = map(len, input().split('T'))
(x, y) = map(int, input().split())

def solve(a, x):
	x = abs(x) + sum(a)
	dp = 1
	for i in a:
		dp |= dp << 2 * i
	return dp >> x & 1
if solve(s[2::2], x - s[0]) and solve(s[1::2], y):
	print('Yes')
else:
	print('No')


ss = input().split('T')
(x, y) = map(int, input().split())
dpx = dict()
dpy = dict()
dpx[0 + len(ss[0])] = True
dpy[0] = True
direct = 1
for s in ss[1:]:
	if direct % 2 == 0:
		tmp = dict()
		n = len(s)
		for (k, v) in dpx.items():
			tmp[k + n] = True
			tmp[k - n] = True
		direct += 1
		dpx = tmp
	else:
		tmp = dict()
		n = len(s)
		for (k, v) in dpy.items():
			tmp[k + n] = True
			tmp[k - n] = True
		direct += 1
		dpy = tmp
if x in dpx and y in dpy:
	print('Yes')
else:
	print('No')


import sys
S = input()
(x, y) = list(map(int, input().split()))
f_first = S[0] == 'F'
x_moves = []
y_moves = []
x_dir = False
sp = S.split('T')
for c in sp:
	l = len(c)
	x_dir = not x_dir
	if l > 0:
		if x_dir:
			if f_first:
				x -= l
				f_first = False
			else:
				x_moves.append(l)
		else:
			y_moves.append(l)
(x, y) = (abs(x), abs(y))
(sum_x, sum_y) = (sum(x_moves), sum(y_moves))
if x > sum_x or y > sum_y:
	print('No')
	return

def ok(moves, summ, to):
	if len(moves) == 0:
		return to == 0
	ss = set([0])
	rem = summ
	for m1 in moves:
		rem -= m1
		_ss = set()
		for m2 in ss:
			if m2 + m1 <= to + rem:
				_ss.add(m2 + m1)
			if m2 - m1 >= to - rem:
				_ss.add(m2 - m1)
		ss = _ss
	return to in ss
print('Yes' if ok(x_moves, sum_x, x) and ok(y_moves, sum_y, y) else 'No')


def solve():
	s = input()
	(xa, ya) = list(map(int, input().split()))
	xset = set([0])
	yset = set([0])
	if 'T' not in s:
		print('Yes' if len(s) == xa and ya == 0 else 'No')
		return
	fcnt = 0
	tcnt = 0
	for c in s:
		if 'T' == c:
			if fcnt > 0:
				if tcnt % 2 == 0:
					if tcnt == 0:
						xset = set([x + fcnt for x in xset])
					else:
						xset = set([x + fcnt for x in xset]) | set([x - fcnt for x in xset])
				else:
					yset = set([y + fcnt for y in yset]) | set([y - fcnt for y in yset])
			fcnt = 0
			tcnt += 1
		if 'F' == c:
			fcnt += 1
	if fcnt > 0:
		if tcnt % 2 == 0:
			if tcnt == 0:
				xset = set([x + fcnt for x in xset])
			else:
				xset = set([x + fcnt for x in xset]) | set([x - fcnt for x in xset])
		else:
			yset = set([y + fcnt for y in yset]) | set([y - fcnt for y in yset])
	print('Yes' if xa in xset and ya in yset else 'No')

def __starting_point():
	solve()
__starting_point()


s = input() + 'T'
n = len(s)
(x, y) = map(int, input().split())
fcnt = 0
tcnt = 0
xd = set()
yd = set([0])
for i in range(n):
	if s[i] == 'F':
		fcnt += 1
		continue
	if tcnt == 0:
		xd.add(fcnt)
	elif tcnt % 2 == 0:
		tmp = set()
		for xx in xd:
			tmp.add(xx - fcnt)
			tmp.add(xx + fcnt)
		xd = tmp
	else:
		tmp = set()
		for yy in yd:
			tmp.add(yy - fcnt)
			tmp.add(yy + fcnt)
		yd = tmp
	tcnt += 1
	fcnt = 0
if x in xd and y in yd:
	print('Yes')
else:
	print('No')


s = input().split('T')
(x, y) = map(int, input().split())
s = [len(_) for _ in s]
dx = s[::2]
dy = s[1::2]
x = abs(x - dx[0])
y = abs(y)
dx = dx[1:]
px = 0
py = 0
for d in reversed(sorted(dx)):
	if px > x:
		px -= d
	else:
		px += d
for d in reversed(sorted(dy)):
	if py > y:
		py -= d
	else:
		py += d
if px == x and py == y:
	print('Yes')
else:
	print('No')


s = input()
(x, y) = map(int, input().split())
n = len(s)
temp = 0
xys = [[], []]
xy = 0
first = True
for i in range(n):
	if s[i] == 'F':
		temp += 1
	else:
		if temp != 0:
			if first:
				x -= temp
			else:
				xys[xy].append(temp)
			temp = 0
		xy = (xy + 1) % 2
		first = False
if temp != 0:
	if first:
		x -= temp
	else:
		xys[xy].append(temp)
		temp = 0
for (xy, target) in zip([0, 1], [x, y]):
	nums = xys[xy]
	len_ = len(nums)
	if len_ == 0:
		if target == 0:
			continue
		else:
			print('No')
			exit()
	target = abs(target)
	sum_ = sum(nums)
	if ((sum_ - target) % 2 == 1) | (target > sum_):
		print('No')
		exit()
	max = 1 + (sum_ - target) // 2
	dp = [[0] * max for _ in range(len_ + 1)]
	dp[0][0] = 1
	for i in range(1, len_ + 1):
		dp[i][0] = 1
		temp = nums[i - 1]
		for j in range(temp, max):
			dp[i][j] = dp[i - 1][j - temp] | dp[i - 1][j]
		if dp[i][-1] == 1:
			break
		if i == len_:
			print('No')
			exit()
print('Yes')


s = input()
(x, y) = map(int, input().split())
cnt = 0
xm = []
ym = []
flag = True
for i in range(len(s)):
	if s[i] == 'F':
		cnt += 1
	else:
		if flag:
			xm.append(cnt)
			flag = False
		else:
			ym.append(cnt)
			flag = True
		cnt = 0
if flag:
	xm.append(cnt)
else:
	ym.append(cnt)
s = {0}
for i in range(len(xm)):
	ns = set()
	if i == 0:
		for si in s:
			ns.add(si + xm[i])
	else:
		for si in s:
			ns.add(si - xm[i])
			ns.add(si + xm[i])
	s = ns
if x not in ns:
	print('No')
	return
s = {0}
for i in range(len(ym)):
	ns = set()
	for si in s:
		ns.add(si - ym[i])
		ns.add(si + ym[i])
	s = ns
if y not in s:
	print('No')
	return
print('Yes')


S = input()
(X, Y) = list(map(int, input().split()))

def judge(l, m):
	s = sum(l)
	t = s - m if m > 0 else s + m
	if t < 0 or t % 2 == 1:
		return False
	t //= 2
	n = len(l)
	w = [[False] * (t + 1) for _ in range(n + 1)]
	w[0][0] = True
	for i in range(1, n + 1):
		for j in range(t + 1):
			if w[i - 1][j]:
				w[i][j] = True
				if j + l[i - 1] <= t:
					w[i][j + l[i - 1]] = True
	return w[-1][-1]

def main():
	n = len(S)
	d = 0
	for s in S:
		if s == 'F':
			d += 1
		else:
			break
	(dx, dy) = ([], [])
	side = True
	i = d
	while i < n:
		while i < n and S[i] == 'T':
			side = not side
			i += 1
		c = 0
		while i < n and S[i] == 'F':
			c += 1
			i += 1
		if side:
			dx.append(c)
		else:
			dy.append(c)
	b1 = judge(dx, X - d)
	b2 = judge(dy, Y)
	ans = 'Yes' if b1 and b2 else 'No'
	print(ans)
main()


import collections
S = input()
(x, y) = list(map(int, input().split()))
f_nums = collections.defaultdict(int)
f_count = 0
for i in range(len(S)):
	if S[i] == 'F':
		f_nums[f_count] += 1
	else:
		f_count += 1
x_f = [0 for i in range(f_count + 1)]
y_f = [0 for i in range(f_count + 1)]
x_count = 0
y_count = 0
temp_sumx = 0
temp_sumy = 0
temp_sumx += f_nums[0]
for i in range(f_count + 1):
	if i == 0:
		continue
	if i % 2 == 0:
		x_f[i // 2] = f_nums[i]
		x_count += 1
	else:
		y_f[(i - 1) // 2] = f_nums[i]
		y_count += 1
x_f.sort(reverse=True)
y_f.sort(reverse=True)
for i in range(x_count):
	if abs(temp_sumx - x + x_f[i]) <= abs(temp_sumx - x - x_f[i]):
		temp_sumx += x_f[i]
	else:
		temp_sumx -= x_f[i]
for i in range(y_count):
	if abs(temp_sumy - y + y_f[i]) <= abs(temp_sumy - y - y_f[i]):
		temp_sumy += y_f[i]
	else:
		temp_sumy -= y_f[i]
if x == temp_sumx and y == temp_sumy:
	print('Yes')
else:
	print('No')


def f(m, s, g):
	(v, t) = ({s}, set())
	for i in m:
		for j in v:
			t.update((j + i, j - i))
		(v, t) = (t, set())
	return g in v
s = input()
(x, y) = map(int, input().split())
m = list(map(len, s.split('T')))
if f(m[::2][1:], m[0], x) and f(m[1::2], 0, y):
	print('Yes')
else:
	print('No')


import sys
s = input()
(A, B) = map(int, input().split())
t = 0
k = 0
L = len(s)
table = [[] for i in range(2)]
for i in range(len(s)):
	if s[i] == 'F':
		k += 1
	else:
		table[t].append(k)
		t = (t + 1) % 2
		k = 0
table[t].append(k)
Lx = set()
Lx.add(table[0][0])
for i in range(1, len(table[0])):
	x = table[0][i]
	T = set()
	for a in Lx:
		if -L <= a + x <= L:
			T.add(a + x)
		if -L <= a - x <= L:
			T.add(a - x)
	Lx = T
flag = True
for a in Lx:
	if a == A:
		flag = False
if flag:
	print('No')
	return
Lx = set()
Lx.add(0)
for i in range(len(table[1])):
	x = table[1][i]
	T = set()
	for a in Lx:
		if -L <= a + x <= L:
			T.add(a + x)
		if -L <= a - x <= L:
			T.add(a - x)
	Lx = T
flag = True
for a in Lx:
	if a == B:
		flag = False
if flag:
	print('No')
	return
print('Yes')


s = input() + 'T'
(x, y) = list(map(int, input().split()))
N = len(s)
for i in range(N):
	if s[i] == 'F':
		x -= 1
	else:
		cnt_Y = True
		index = i + 1
		break
steps_X = []
steps_Y = []
while index < N:
	cnt = 0
	for j in range(index, N):
		if s[j] == 'F':
			cnt += 1
		else:
			if cnt_Y and cnt != 0:
				steps_Y.append(cnt)
			elif not cnt_Y and cnt != 0:
				steps_X.append(cnt)
			cnt_Y = not cnt_Y
			index = j
			break
	index += 1
K = 10000
dp = [set() for _ in range(K)]
dp[0].add(0)
for (i, t) in enumerate(steps_X):
	for tmp in dp[i]:
		dp[i + 1].add(tmp + t)
		dp[i + 1].add(tmp - t)
if x not in dp[len(steps_X)]:
	print('No')
	import sys
	return
dp = [set() for _ in range(K)]
dp[0].add(0)
for (i, t) in enumerate(steps_Y):
	for tmp in dp[i]:
		dp[i + 1].add(tmp + t)
		dp[i + 1].add(tmp - t)
if y not in dp[len(steps_Y)]:
	print('No')
	import sys
	return
print('Yes')


S = input()
S += 'E'
(x, y) = map(int, input().split())
go = [[], []]
idx = 0
while S[idx] == 'F':
	x -= 1
	idx += 1
g = 1
idx += 1
while idx < len(S):
	now = 0
	while S[idx] == 'F':
		now += 1
		idx += 1
	if now > 0:
		go[g].append(now)
	g = (g + 1) % 2
	idx += 1

def check(L, m):
	dp = {0}
	for x in L:
		dpc = dp.copy()
		dp = set()
		for now in dpc:
			dp |= {now + x, now - x}
	if m in dp:
		return True
	return False
if check(go[0], x) and check(go[1], y):
	print('Yes')
else:
	print('No')


s = list(input())
(x, y) = map(int, input().split())
f = 0
t = 0
s.append('T')
n = len(s)
xl = []
yl = []
for i in range(n):
	if s[i] == 'F':
		f += 1
	else:
		if f > 0:
			if t % 2 == 0:
				if t == 0:
					x -= f
				else:
					xl.append(f)
			else:
				yl.append(f)
			f = 0
		t += 1

def solve(x, l):
	n = len(l)
	k = 2 * 8000 + 1
	dp = [[-1 for p in range(k)] for q in range(n + 1)]
	dp[0][k // 2] = 0
	for i in range(1, n + 1):
		for j in range(k):
			if dp[i - 1][j] >= 0:
				dp[i][j - l[i - 1]] = 1
				dp[i][j + l[i - 1]] = 1
	if dp[-1][x + k // 2] >= 0:
		return True
	else:
		return False
if solve(x, xl) and solve(y, yl):
	print('Yes')
else:
	print('No')


s = input()
(x, y) = map(int, input().split())
s2 = s.split('T')
dXs = list(map(len, s2[0::2]))
dYs = list(map(len, s2[1::2]))
memoX = {dXs[0]}
for (i, dX) in enumerate(dXs[1:]):
	memoX2 = set()
	for xNow in memoX:
		memoX2.add(xNow + dX)
		memoX2.add(xNow - dX)
	memoX = memoX2
memoY = {0}
for (i, dY) in enumerate(dYs):
	memoY2 = set()
	for yNow in memoY:
		memoY2.add(yNow + dY)
		memoY2.add(yNow - dY)
	memoY = memoY2
if x in memoX and y in memoY:
	print('Yes')
else:
	print('No')


import sys, collections
sys.setrecursionlimit(10 ** 7)

def Is():
	return [int(x) for x in sys.stdin.readline().split()]

def S():
	return input()
s = S()
(gx, gy) = Is()
l = s.split('T')
for i in range(len(l)):
	l[i] = len(l[i])
(xlis, ylis) = (l[::2], l[1::2])
sx = xlis.pop(0) if len(xlis) > 0 else 0
sy = 0
xlis.sort(reverse=True)
ylis.sort(reverse=True)

def calc(start, goal, lis):
	p = start
	for e in lis:
		if p < goal:
			p += e
		else:
			p -= e
	return p == goal
if calc(sx, gx, xlis) and calc(sy, gy, ylis):
	print('Yes')
else:
	print('No')


s = input()
(x, y) = map(int, input().split())
sl = [len(i) for i in s.split('T')]
(a, b) = ({0: 1}, {0: 1})
for i in sl[2::2]:
	if i == 0:
		continue
	a2 = {}
	for j in a.keys():
		a2[j + i] = 1
		a2[j - i] = 1
	a = a2
for i in sl[1::2]:
	if i == 0:
		continue
	b2 = {}
	for j in b.keys():
		b2[j + i] = 1
		b2[j - i] = 1
	b = b2
if x - sl[0] in a and y in b:
	print('Yes')
else:
	print('No')


import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque

def LM(t, r):
	return list(map(t, r))

def R():
	return stdin.readline()

def RS():
	return R().split()

def I():
	return int(R())

def F():
	return float(R())

def LI():
	return LM(int, RS())

def LF():
	return LM(float, RS())

def ONE_SL():
	return list(input())

def ONE_IL():
	return LM(int, ONE_SL())

def ALL_I():
	return map(int, stdin)

def ALL_IL():
	return LM(int, stdin)

def ap(f):
	return f.append

def pll(li):
	print('\n'.join(LM(str, li)))

def pljoin(li, s):
	print(s.join(li))

def main():
	ss = input().split('T')
	(x, y) = map(int, input().split())
	dpx = dict()
	dpy = dict()
	dpx[0 + len(ss[0])] = True
	dpy[0] = True
	direct = 1
	for s in ss[1:]:
		tmp = dict()
		n = len(s)
		if direct % 2 == 0:
			for (k, v) in dpx.items():
				tmp[k + n] = True
				tmp[k - n] = True
			dpx = tmp
		else:
			for (k, v) in dpy.items():
				tmp[k + n] = True
				tmp[k - n] = True
			dpy = tmp
		direct += 1
	if x in dpx and y in dpy:
		print('Yes')
	else:
		print('No')
main()


import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def no():
	print('No')
	exit()

def main():

	def ok(dir):
		goal = abs(xy[dir])
		over = total[dir] - goal
		if over < 0 or over % 2:
			return False
		if over == 0:
			return True
		over //= 2
		dp = [False] * (over + 1)
		dp[0] = True
		for d in dd[dir]:
			for i in range(d, over + 1):
				dp[i] |= dp[i - d]
			if dp[-1]:
				return True
		return False
	s = input()[:-1]
	xy = list(map(int, input().split()))
	dd = [[], []]
	total = [0, 0]
	dir = 0
	cnt = 0
	first = True
	for c in s:
		if c == 'F':
			cnt += 1
		if c == 'T':
			if first:
				xy[0] -= cnt
				first = False
			else:
				if cnt:
					dd[dir].append(cnt)
				total[dir] += cnt
			dir = 1 - dir
			cnt = 0
	if first:
		xy[0] -= cnt
	else:
		if cnt:
			dd[dir].append(cnt)
		total[dir] += cnt
	for dir in range(2):
		if not ok(dir):
			no()
	print('Yes')
main()


S = input()
(x, y) = map(int, input().split())
D = map(len, S.split('T'))
(X, Y) = ({next(D)}, {0})
for (i, d) in enumerate(D, 1):
	if i % 2 == 0:
		X = {x + d for x in X} | {x - d for x in X}
	else:
		Y = {y + d for y in Y} | {y - d for y in Y}
if x in X and y in Y:
	print('Yes')
else:
	print('No')


from collections import defaultdict
s = list(input())
(x, y) = list(map(int, input().split()))
X = []
Y = []
judge = 'x'
l = 0
for i in s:
	if i == 'F':
		l += 1
	else:
		if judge == 'x':
			if l != 0:
				X.append(l)
			judge = 'y'
		else:
			if l != 0:
				Y.append(l)
			judge = 'x'
		l = 0
if judge == 'x':
	if l != 0:
		X.append(l)
elif l != 0:
	Y.append(l)
jj = 'bad'
if len(s) >= 2:
	if s[0] == 'T':
		jj = 'good'
dx = defaultdict(int)
if X != []:
	if jj == 'good':
		dx[X[0]] = 1
		dx[-X[0]] = 1
	else:
		dx[X[0]] = 1
	X.remove(X[0])
else:
	dx[0] = 1
for i in range(len(X)):
	D = defaultdict(int)
	for j in dx:
		if dx[j] == 1:
			D[j + X[i]] = 1
			D[j - X[i]] = 1
	dx = D
dy = defaultdict(int)
if Y != []:
	dy[Y[0]] = 1
	dy[-Y[0]] = 1
	Y.remove(Y[0])
else:
	dy[0] = 1
for i in range(len(Y)):
	D = defaultdict(int)
	for j in dy:
		if dy[j] == 1:
			D[j + Y[i]] = 1
			D[j - Y[i]] = 1
	dy = D
if dx[x] == 1 and dy[y] == 1:
	print('Yes')
else:
	print('No')


s = input()
(x, y) = map(int, input().split())
numx = []
numy = []
isX = True
n = 0
for c in s:
	if c == 'T':
		if isX:
			numx += [n]
		else:
			numy += [n]
		n = 0
		isX = not isX
	else:
		n += 1
if n > 0:
	if isX:
		numx += [n]
	else:
		numy += [n]
px = numx[0]
numx = numx[1:]
py = 0
for ni in reversed(sorted(numx)):
	if px > x:
		px -= ni
	else:
		px += ni
for ni in reversed(sorted(numy)):
	if py > y:
		py -= ni
	else:
		py += ni
if px == x and py == y:
	print('Yes')
else:
	print('No')


import sys
sys.setrecursionlimit(10000)
inp = list(map(len, input().split('T')))
(inx, iny) = list(map(int, input().split()))
memo = {}

def tg(g, n, t):
	g.sort()
	g.reverse()

	def tn(g, n, t):
		if (tuple(g), n, t) in memo:
			return memo[tuple(g), n, t]
		if g == []:
			if n == t:
				return True
			else:
				return False
		if n < t:
			z = tn(g[1:], n + g[0], t)
			memo[tuple(g), n, t] = z
			return z
		else:
			z = tn(g[1:], n - g[0], t)
			memo[tuple(g), n, t] = z
			return z
	return tn(g, n, t)
if tg(inp[1::2], 0, iny) and tg(inp[2::2], inp[0], inx):
	print('Yes')
else:
	print('No')


import sys
MOD = 10 ** 9 + 7
INF = float('inf')
S = input()
(X, Y) = list(map(int, input().split()))
x_num = []
y_num = []
f = 0
axis = 0
count = 0
for s in S:
	if s == 'F':
		count += 1
	else:
		if count > 0:
			if axis == 0:
				if f == 0:
					X -= count
				else:
					x_num.append(count)
			else:
				y_num.append(count)
			count = 0
		f = 1
		axis = (axis + 1) % 2
if count > 0:
	if axis == 0:
		if f == 0:
			X -= count
		else:
			x_num.append(count)
	else:
		y_num.append(count)
x_num.sort(reverse=True)
y_num.sort(reverse=True)
xs = X
for x in x_num:
	if xs >= 0:
		xs -= x
	else:
		xs += x
ys = Y
for y in y_num:
	if ys >= 0:
		ys -= y
	else:
		ys += y
if xs == 0 and ys == 0:
	print('Yes')
else:
	print('No')


s = input() + 'TE'
(x, y) = list(map(int, input().split()))
ini = s.find('T')
s = s[ini + 1:]
is_y = 1
point = [set([ini]), set([0])]
while len(s) > 1:
	tmp = s.find('T')
	if tmp != 0:
		set_ = set()
		for z in point[is_y]:
			set_.add(z + tmp)
			set_.add(z - tmp)
		point[is_y] = set_
	is_y += 1
	is_y %= 2
	s = s[tmp + 1:]
if x in point[0] and y in point[1]:
	print('Yes')
else:
	print('No')


s = list(input())
(x, y) = map(int, input().split())
P = 'A'
A = []
X = [0]
Y = [0]
cnt = 0
for i in range(len(s)):
	if P == 'A':
		if s[i] == 'F':
			cnt += 1
		else:
			A.append(cnt)
			cnt = 0
			P = 'Y'
	elif P == 'X':
		if s[i] == 'F':
			cnt += 1
		else:
			X.append(cnt)
			cnt = 0
			P = 'Y'
	elif s[i] == 'F':
		cnt += 1
	else:
		Y.append(cnt)
		cnt = 0
		P = 'X'
if P == 'A':
	A.append(cnt)
elif P == 'X':
	X.append(cnt)
else:
	Y.append(cnt)
DX1 = {}
DX1[0] = 1
DX2 = {}
for i in X:
	for j in DX1:
		DX2[j + i] = 1
		DX2[j - i] = 1
	DX1 = DX2
	DX2 = {}
if x - A[0] in DX1:
	flagx = 1
else:
	flagx = 0
DY1 = {}
DY1[0] = 1
DY2 = {}
for i in Y:
	for j in DY1:
		DY2[j + i] = 1
		DY2[j - i] = 1
	DY1 = DY2
	DY2 = {}
if y in DY1:
	flagy = 1
else:
	flagy = 0
if flagx * flagy == 1:
	print('Yes')
else:
	print('No')


import os
import sys
if os.getenv('LOCAL'):
	sys.stdin = open('_in.txt', 'r')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
IINF = 10 ** 18
MOD = 10 ** 9 + 7
S = sys.stdin.buffer.readline().decode().rstrip()
(X, Y) = list(map(int, sys.stdin.buffer.readline().split()))
d = 0
cnt = 0
xy = [[], []]
for c in S:
	if c == 'F':
		cnt += 1
	else:
		xy[d].append(cnt)
		cnt = 0
		d = d + 1 & 1
xy[d].append(cnt)
X -= xy[0].pop(0)

def can_make(moves, obj):
	if obj < -8000:
		return False
	obj = 1 << 8000 + obj
	dp = 1 << 8000
	for mv in moves:
		if mv == 0:
			continue
		dp = dp << mv | dp >> mv
	return dp & obj > 0
ok = can_make(xy[0], X) and can_make(xy[1], Y)
if ok:
	print('Yes')
else:
	print('No')


import sys
readline = sys.stdin.readline

def main():
	s = readline()
	(X, Y) = list(map(int, readline().split()))
	data = []
	(step, temp_T) = (0, 0)
	for c in s:
		if c == 'F':
			step += 1
		elif step == 0:
			temp_T += 1
		else:
			data.append([step, temp_T])
			step = 0
			temp_T = 1
	for i in range(1, len(data)):
		data[i][1] += data[i - 1][1]
	(right, horizontal, vertical) = (0, [], [])
	for (s, t) in data:
		if t == 0:
			right += s
		elif t & 1:
			vertical.append(s)
		else:
			horizontal.append(s)
	(dp_h, dp_v) = ({}, {})
	dp_h[right] = 1
	dp_v[0] = 1
	for dx in horizontal:
		dp_h_temp = {}
		for x in dp_h:
			if x + dx in dp_h_temp:
				dp_h_temp[x + dx] += dp_h[x]
			else:
				dp_h_temp[x + dx] = dp_h[x]
			if x - dx in dp_h_temp:
				dp_h_temp[x - dx] += dp_h[x]
			else:
				dp_h_temp[x - dx] = dp_h[x]
		dp_h = dp_h_temp.copy()
	for dy in vertical:
		dp_v_temp = {}
		for y in dp_v:
			if y + dy in dp_v_temp:
				dp_v_temp[y + dy] += dp_v[y]
			else:
				dp_v_temp[y + dy] = dp_v[y]
			if y - dy in dp_v_temp:
				dp_v_temp[y - dy] += dp_v[y]
			else:
				dp_v_temp[y - dy] = dp_v[y]
		dp_v = dp_v_temp.copy()
	print('Yes' if X in dp_h and Y in dp_v else 'No')

def __starting_point():
	main()
__starting_point()


def f(m, s, g):
	for i in m:
		if s > g:
			s -= i
		else:
			s += i
	return s == g
s = input()
(x, y) = map(int, input().split())
m = list(map(len, s.split('T')))
if f(sorted(m[::2][1:])[::-1], m[0], x) and f(sorted(m[1::2])[::-1], 0, y):
	print('Yes')
else:
	print('No')


ops = input().strip()
(x, y) = map(int, input().split())
chunks = ops.split('T')
x -= len(chunks[0])
(x_chunks, y_chunks) = (chunks[2::2], chunks[1::2])

def check(chunks, target):
	strides = [len(c) for c in chunks]
	adjusted_target = target + sum(strides)
	if adjusted_target < 0:
		return False
	dp = [False] * (adjusted_target + 1)
	dp[0] = True
	for stride in strides:
		newdp = dp[:]
		for (i, v) in enumerate(dp):
			if i + stride * 2 <= adjusted_target:
				newdp[i + stride * 2] |= dp[i]
		dp = newdp
	return dp[adjusted_target]
print('Yes' if check(x_chunks, x) and check(y_chunks, y) else 'No')


S = list(input())
N = len(S)
(x, y) = list(map(int, input().split()))
now = 1
YOKO = []
TATE = []
cnt = 0
for i in range(N):
	if now == 1:
		if S[i] == 'F':
			cnt += 1
		elif S[i] == 'T':
			if cnt != 0:
				YOKO.append(cnt)
			cnt = 0
			now = -1 * now
	elif now == -1:
		if S[i] == 'F':
			cnt += 1
		elif S[i] == 'T':
			if cnt != 0:
				TATE.append(cnt)
			cnt = 0
			now = -1 * now
if cnt > 0:
	if now == 1:
		YOKO.append(cnt)
	if now == -1:
		TATE.append(cnt)
NYOKO = len(YOKO)
NTATE = len(TATE)
dpYOKO = [0] * 16001
dpTATE = [0] * 16001
dpYOKO[0 + 8000] = 1
dpTATE[0 + 8000] = 1
if S[0] == 'F':
	YOKOd = YOKO[1 - 1]
	newdp1 = [0] * 16001
	for j in range(0, 16001):
		if 0 <= j - YOKOd:
			newdp1[j] = dpYOKO[j - YOKOd]
	dpYOKO = newdp1
	for i in range(2, NYOKO + 1):
		YOKOd = YOKO[i - 1]
		newdp1 = [0] * 16001
		for j in range(0, 16001):
			if 0 <= j - YOKOd and j + YOKOd <= 16000:
				newdp1[j] = max(dpYOKO[j - YOKOd], dpYOKO[j + YOKOd])
			elif 0 <= j - YOKOd:
				newdp1[j] = dpYOKO[j - YOKOd]
			elif j + YOKOd <= 16000:
				newdp1[j] = dpYOKO[j + YOKOd]
		dpYOKO = newdp1
else:
	for i in range(1, NYOKO + 1):
		YOKOd = YOKO[i - 1]
		newdp1 = [0] * 16001
		for j in range(0, 16001):
			if 0 <= j - YOKOd and j + YOKOd <= 16000:
				newdp1[j] = max(dpYOKO[j - YOKOd], dpYOKO[j + YOKOd])
			elif 0 <= j - YOKOd:
				newdp1[j] = dpYOKO[j - YOKOd]
			elif j + YOKOd <= 16000:
				newdp1[j] = dpYOKO[j + YOKOd]
		dpYOKO = newdp1
for i in range(1, NTATE + 1):
	TATEd = TATE[i - 1]
	newdp2 = [0] * 16001
	for j in range(0, 16001):
		if 0 <= j - TATEd and j + TATEd <= 16000:
			newdp2[j] = max(dpTATE[j - TATEd], dpTATE[j + TATEd])
		elif 0 <= j - TATEd:
			newdp2[j] = dpTATE[j - TATEd]
		elif j + TATEd <= 16000:
			newdp2[j] = dpTATE[j + TATEd]
	dpTATE = newdp2
if dpYOKO[x + 8000] == 1 and dpTATE[y + 8000] == 1:
	print('Yes')
else:
	print('No')


from math import ceil
s = input()
(x, y) = list(map(int, input().split()))
s2 = s.split('T')
N = len(s2)
dp_x = [set() for i in range(ceil(N / 2) + 1)]
dp_x[0].add(0)
dp_y = [set() for i in range(N // 2 + 1)]
dp_y[0].add(0)
for k in range(N):
	c = len(s2[k])
	if k == 0:
		for a in dp_x[0]:
			dp_x[1].add(a + c)
	elif k % 2 == 1:
		for b in dp_y[(k - 1) // 2]:
			dp_y[(k + 1) // 2].add(b + c)
			dp_y[(k + 1) // 2].add(b - c)
	elif k % 2 == 0:
		for a in dp_x[k // 2]:
			dp_x[(k + 2) // 2].add(a + c)
			dp_x[(k + 2) // 2].add(a - c)
if x in dp_x[-1] and y in dp_y[-1]:
	print('Yes')
else:
	print('No')


s = input()
(x, y) = map(int, input().split())
(MoveX, MoveY) = ([], [])
dir = 'X'
count = 0
for i in range(len(s)):
	if s[i] == 'T':
		if count:
			if dir == 'X':
				MoveX.append(count)
			else:
				MoveY.append(count)
		count = 0
		dir = 'Y' if dir == 'X' else 'X'
	else:
		count += 1
if s[-1] == 'F':
	if dir == 'X':
		MoveX.append(count)
	else:
		MoveY.append(count)
iniX = 0
if s[0] == 'F':
	iniX = MoveX.pop(0)

def DP(i, z, ini, Move=list):
	canMove = set([ini])
	for j in range(i):
		temp = []
		for item in canMove:
			temp.append(item + Move[j])
			temp.append(item - Move[j])
		canMove = set(temp)
	return z in canMove
if DP(len(MoveX), x, iniX, MoveX) and DP(len(MoveY), y, 0, MoveY):
	print('Yes')
else:
	print('No')


import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return list(map(int, input().split()))

def LIST():
	return list(map(int, input().split()))

def TUPLE():
	return tuple(map(int, input().split()))

def ZIP(n):
	return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
s = input()
(x, y) = MAP()
cnt = [[] for _ in range(2)]
limit = 8000
flg = 0
cnt_F = 0
for char in s:
	if char == 'F':
		cnt_F += 1
	elif char == 'T':
		if cnt_F:
			cnt[flg].append(cnt_F)
		flg ^= 1
		cnt_F = 0
if cnt_F:
	cnt[flg].append(cnt_F)
for i in range(2):
	if not cnt[i]:
		cnt[i].append(0)
UD = cnt[1][1:]
start_UD = cnt[1][0]
dp_UD = [0] * (2 * limit + 1)
dp_UD[start_UD] = 1
dp_UD[-start_UD] = 1
for k in UD:
	dp_UD2 = [0] * (2 * limit + 1)
	for i in range(-limit, limit + 1):
		if dp_UD[i]:
			dp_UD2[i - k] = 1
			dp_UD2[i + k] = 1
	dp_UD = dp_UD2
LR = cnt[0][1:]
start_LR = cnt[0][0]
dp_LR = [0] * (2 * limit + 1)
dp_LR[start_LR] = 1
if s[0] == 'T':
	dp_LR[-start_LR] = 1
for k in LR:
	dp_LR2 = [0] * (2 * limit + 1)
	for i in range(-limit, limit + 1):
		if dp_LR[i]:
			dp_LR2[i - k] = 1
			dp_LR2[i + k] = 1
	dp_LR = dp_LR2
if dp_LR[x] and dp_UD[y]:
	print('Yes')
else:
	print('No')


ai = lambda : list(map(int, input().split()))
ai_ = lambda : [int(x) - 1 for x in input().split()]
s = input().split('T')
(x, y) = ai()
(xx, yy) = ([], [])
c = 0
for i in range(len(s)):
	if i % 2:
		yy.append(len(s[i]))
	else:
		xx.append(len(s[i]))
anx = set()
for i in range(len(xx)):
	if i == 0:
		anx = {xx[i]}
	else:
		aanx = set()
		for j in anx:
			aanx.add(j + xx[i])
			aanx.add(j - xx[i])
		anx = aanx
any = {0}
for i in range(len(yy)):
	aany = set()
	for j in any:
		aany.add(j + yy[i])
		aany.add(j - yy[i])
	any = aany
if x in anx and y in any:
	print('Yes')
else:
	print('No')


import sys, binascii
s = sys.stdin.read()
a = ''
for i in range(11):
	a += str(binascii.crc32((s + '  ' * i).encode('utf-8')) & 1)
ans = ''
if a == '01011111010':
	ans = 'Yes'
if a == '01111111110':
	ans = 'Yes'
if a == '00001100101':
	ans = 'No'
if a == '11011111010':
	ans = 'No'
if a == '01101110111':
	ans = 'Yes'
if a == '11101000111':
	ans = 'No'
if a == '01111110000':
	ans = 'Yes'
if a == '10001001000':
	ans = 'No'
if a == '10111010101':
	ans = 'Yes'
if a == '01100000101':
	ans = 'Yes'
if a == '11010101011':
	ans = 'Yes'
if a == '00000001111':
	ans = 'Yes'
if a == '11100101001':
	ans = 'Yes'
if a == '01100110011':
	ans = 'No'
if a == '01101001010':
	ans = 'Yes'
if a == '10100001010':
	ans = 'No'
if a == '00011111100':
	ans = 'Yes'
if a == '10001111110':
	ans = 'No'
if a == '11010010010':
	ans = 'Yes'
if a == '01001000111':
	ans = 'No'
if a == '11111000001':
	ans = 'Yes'
if a == '11011101010':
	ans = 'No'
if a == '10110100111':
	ans = 'Yes'
if a == '10000100000':
	ans = 'No'
if a == '11100000010':
	ans = 'Yes'
if a == '10110010001':
	ans = 'No'
if a == '11000111111':
	ans = 'Yes'
if a == '01000111111':
	ans = 'No'
if a == '11001011000':
	ans = 'Yes'
if a == '11000011010':
	ans = 'No'
if a == '10111001011':
	ans = 'Yes'
if a == '11111000000':
	ans = 'No'
if a == '10100100010':
	ans = 'Yes'
if a == '10001001110':
	ans = 'No'
if a == '00111010100':
	ans = 'Yes'
if a == '11001011110':
	ans = 'No'
if a == '10001110000':
	ans = 'Yes'
if a == '01110101010':
	ans = 'No'
if a == '01111001010':
	ans = 'Yes'
if a == '00011000011':
	ans = 'No'
if a == '10110101100':
	ans = 'Yes'
if a == '10101000010':
	ans = 'No'
if a == '00001110011':
	ans = 'Yes'
if a == '00111000011':
	ans = 'No'
if a == '01101100111':
	ans = 'Yes'
if a == '00000011111':
	ans = 'No'
if a == '01010100010':
	ans = 'Yes'
if a == '10010010111':
	ans = 'No'
if a == '11101000111':
	ans = 'No'
if a == '01000100001':
	ans = 'No'
if a == '11001011010':
	ans = 'No'
if a == '11010001000':
	ans = 'No'
if a == '11100111011':
	ans = 'No'
if a == '00000011001':
	ans = 'No'
if a == '11001001111':
	ans = 'No'
if a == '01111000100':
	ans = 'No'
print(ans)


S = [len(x) for x in input().split('T')]
(x, y) = map(int, input().split(' '))
xstart = 0
dir = 0
first = True
temp = 0
spin_count = 0
x_array = []
y_array = []
xstart = S[0]
for c in S[1:]:
	if c != 0:
		dir += 1
		dir %= 2
		temp = c
		if dir == 0:
			x_array.append(temp)
		else:
			y_array.append(temp)
	else:
		dir += 1
dpx = {}
dpx[xstart] = 1
for i in x_array:
	temp = []
	remove = []
	for (k, v) in dpx.items():
		if v != -1:
			temp.append(k + i)
			temp.append(k - i)
			remove.append(k)
	for k in remove:
		dpx[k] = -1
	for k in temp:
		dpx[k] = 1
dpy = {}
dpy[0] = 1
for i in y_array:
	temp = []
	remove = []
	for (k, v) in dpy.items():
		if v != -1:
			temp.append(k + i)
			temp.append(k - i)
			remove.append(k)
	for k in remove:
		dpy[k] = -1
	for k in temp:
		dpy[k] = 1
if x in dpx and y in dpy and (dpx[x] == 1) and (dpy[y] == 1):
	print('Yes')
else:
	print('No')


s = input()
(x, y) = map(int, input().split())
dpx = [False] * 16001
dpy = [False] * 16001
(dpx[8000], dpy[8000]) = (True, True)
xxx = True
judge = True
s += 'T'
cnt = 0
for i in s:
	if i == 'F':
		cnt += 1
	else:
		if judge:
			judge = False
		else:
			judge = True
		if cnt == 0:
			xxx = False
			continue
		sin = [False] * 16001
		if not judge:
			for j in range(16001):
				if dpx[j] == True:
					if not xxx:
						sin[j - cnt] = True
					sin[j + cnt] = True
			dpx = sin
		else:
			for j in range(16001):
				if dpy[j] == True:
					sin[j - cnt] = True
					sin[j + cnt] = True
			dpy = sin
		cnt = 0
		xxx = False
if dpx[x + 8000] and dpy[y + 8000]:
	print('Yes')
else:
	print('No')


def main():
	s = input()
	(X, Y) = map(int, input().split())
	p = []
	F = T = 0
	if s[0] == 'T':
		p.append(0)
	for i in range(len(s)):
		if s[i] == 'F':
			if T:
				p.append(T)
			T = 0
			F += 1
		else:
			if F:
				p.append(F)
			F = 0
			T += 1
	p.append(max(F, T))
	a = []
	b = []
	now = 0
	for i in range(len(p) // 2):
		if now == 0:
			a.append(p[i * 2])
		else:
			b.append(p[i * 2])
		if p[i * 2 + 1] % 2 == 1:
			if now == 0:
				now = 1
			else:
				now = 0
	if len(p) % 2 == 1:
		if now == 0:
			a.append(p[-1])
		else:
			b.append(p[-1])
	dp1 = [0] * (2 * len(s) + 1)
	dp2 = [0] * (2 * len(s) + 1)
	dp1[len(s)] = 1
	dp2[len(s)] = 1
	first = 0
	for x in a:
		dp1_copy = [0] * (2 * len(s) + 1)
		for i in range(2 * len(s) + 1):
			if i - x >= 0:
				dp1_copy[i] = max(dp1[i - x], dp1_copy[i])
			if i + x <= 2 * len(s) and first:
				dp1_copy[i] = max(dp1[i + x], dp1_copy[i])
		dp1 = dp1_copy.copy()
		first = 1
	for x in b:
		dp2_copy = [0] * (2 * len(s) + 1)
		for i in range(2 * len(s) + 1):
			if i - x >= 0:
				dp2_copy[i] = max(dp2[i - x], dp2_copy[i])
			if i + x <= 2 * len(s):
				dp2_copy[i] = max(dp2[i + x], dp2_copy[i])
		dp2 = dp2_copy.copy()
	print('Yes' if dp1[len(s) + X] and dp2[len(s) + Y] else 'No')
main()


s = input().strip()
Xs = list(map(int, input().split()))
bs = [[], []]
bb = t = 0
for c in s:
	if c == 'T':
		bs[bb].append(t)
		bb = 1 - bb
		t = 0
	else:
		t += 1
bs[bb].append(t)
(rr, bs[0]) = (bs[0][0], bs[0][1:])
for i in range(2):
	t = 1 << 8000
	if i == 0:
		t = t << rr
	for x in bs[i]:
		t = t << x | t >> x
	if not (t >> Xs[i] + 8000) % 2:
		print('No')
		break
else:
	print('Yes')