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

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')


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 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()


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')


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()
(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')


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')


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 = 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()


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')


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')


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')


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')