Problem:
 Score : 500 points    Problem Statement A robot is put at the origin in a two-dimensional plane.
Initially, the robot is facing in the positive x -axis direction.  This robot will be given an instruction sequence s . s consists of the following two kinds of letters, and will be executed in order from front to back.   F : Move in the current direction by distance 1 .  T : Turn 90 degrees, either clockwise or counterclockwise.   The objective of the robot is to be at coordinates (x, y) after all the instructions are executed.
Determine whether this objective is achievable.      Constraints  s consists of F and T .  1 \leq |s| \leq 8  000  x and y are integers.  |x|, |y| \leq |s|         Input Input is given from Standard Input in the following format:  s  x  y       Output If the objective is achievable, print Yes ; if it is not, print No .        Sample Input 1 FTFFTFFF
4 2      Sample Output 1 Yes  The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T .       Sample Input 2 FTFFTFFF
-2 -2      Sample Output 2 Yes  The objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T .       Sample Input 3 FF
1 0      Sample Output 3 No       Sample Input 4 TF
1 0      Sample Output 4 No       Sample Input 5 FFTTFF
0 0      Sample Output 5 Yes  The objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T .       Sample Input 6 TTTT
1 0      Sample Output 6 No

Solution (Python):
from math import ceil
s=input()
x,y=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")

Solution (Python):
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)

Solution (Python):

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

Solution (Python):
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')

Solution (Python):
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')

Solution (Python):
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')
    sys.exit()

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')
    sys.exit()
print('Yes')

Solution (Python):
from sys import exit, 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")

Solution (Python):
import sys
s=input()
A,B =map(int,input().split())
table=[[] for i in range(2)]
t = 0
k=0
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)
L=len(s)
Lx=[set() for i in range(len(table[0]) +1)]
Ly=[set() for i in range(len(table[1]) +1)]
Lx[0].add(0)
Ly[0].add(0)
for i in range(len(table[0])):
    x = table[0][i]
    if i==0:
        Lx[1].add(x)
        continue
    for a in Lx[i]:
        if -L<=a+x<=L:
            Lx[i+1].add(a+x)
        if -L<=a-x<=L:
            Lx[i+1].add(a-x) 
flag=True
for a in Lx[len(table[0])]:
    if a==A:
        flag =False
if flag:
    print('No')
    sys.exit()
    
for i in range(len(table[1])):
    x = table[1][i]
    for a in Ly[i]:
        if -L<=a+x<=L:
            Ly[i+1].add(a+x)
        if -L<=a-x<=L:
            Ly[i+1].add(a-x)
flag=True
for a in Ly[len(table[1])]:
    if a==B:
        flag =False
if flag:
    print('No')
    sys.exit()
    
print('Yes')

Solution (Python):


import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq





def solve(f):
    s = f.read_str()
    x, y = f.read_int_list()

    l = s.split('T')
    x0 = len(l[0])

    ys = {0}
    for i in l[1::2]:
        ys2 = set()
        yi = len(i)
        for item in ys:
            ys2.add(item+yi)
            ys2.add(item-yi)
        ys = ys2

    if y not in ys: return 'No'

    xs = {x0}
    for i in l[2::2]:
        xs2 = set()
        xi = len(i)
        for item in xs:
            xs2.add(item+xi)
            xs2.add(item-xi)
        xs = xs2

    if x not in xs: return 'No'

    return 'Yes'


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case 
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

Solution (Python):
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")

Solution (Python):
from collections import defaultdict as dd

s = raw_input().strip()
n = len(s)
x, y = map(int, raw_input().strip().split())

stx = 0
while stx < n and s[stx] == "F":
    stx += 1

sty = 0

X, Y = range(2)

x_blocks = []
y_blocks = []
curr = 0
cdi = X

for i in xrange(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.iterkeys():
        nxt[key + xb] += 1
        nxt[key - xb] += 1

    curr = nxt

if x not in curr:
    print "No"
    exit()

curr = dd(int)
curr[sty] = 1

for yb in y_blocks:
    nxt = dd(int)

    for key in curr.iterkeys():
        nxt[key + yb] += 1
        nxt[key - yb] += 1

    curr = nxt

if y not in curr:
    print "No"
else:
    print "Yes"

Solution (Python):
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')

Solution (Python):
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")

Solution (Python):
def c(p, g, lis):
    for e in lis:
        if p <= g:
            p += e
        else:
            p -= e
    return p == g


if __name__ == '__main__':
    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")

Solution (Python):
import sys

import numpy as np

s = raw_input()
x, y = [int(x) for x in raw_input().split(" ")]

s = s + "T"

a = []
b = []

cum_len = 0
turn = 0
for command in s:
    if command == "F":
        cum_len += 1
    elif command == "T":
        (a if turn == 0 else b).append(cum_len)
        turn ^= 1
        cum_len = 0

a0 = a.pop(0)

alpha = abs(x-a0)
beta = abs(y)

targetX = sum(a) - alpha
targetY = sum(b) - beta

def search(a, target):
    forwardTable = np.zeros((len(a), target+1))
    forwardTable[:,0] = 1
    for i_i in xrange(len(a)):
        new_item = a[i_i]
        if i_i == 0:
            forwardTable[i_i, 2*new_item:2*new_item+1] = 1
        else:
            forwardTable[i_i] += forwardTable[i_i-1]
            if new_item>0:
                forwardTable[i_i,2*new_item:] += forwardTable[i_i-1,:-2*new_item]
        if forwardTable[i_i,-1] > 0:
            forwardTable[-1,-1] = 1
            break

    return (forwardTable[-1,-1]>0)

if (targetX < 0) or (targetY < 0):
    print "No"
    sys.exit()
else:
    if (targetX > 0):
        if not search(a, targetX):
            print "No"
            sys.exit()
    if (targetY > 0):
        if not search(b, targetY):
            print "No"
            sys.exit()
    print "Yes"

Solution (Python):
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')


if __name__ == '__main__':
	main()

Solution (Python):


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

Solution (Python):
s = input() + "T"
x, y = 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
    sys.exit()

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
    sys.exit()


print("Yes")

Solution (Python):
s = input() + "T"
x, y = 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
    sys.exit()

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
    sys.exit()


print("Yes")

Solution (Python):
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)
        else:
            if 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))

if __name__ == '__main__':
    main()

Solution (Python):
s = raw_input()
fx, fy = map(int, raw_input().split())

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

def solve(s, fx, fy):
    try:
        first = s.index('T')
    except:
        return fy == 0 and fx == len(s)
    fx -= first
    s = s[first:]
    ts = []
    for i in range(len(s)):
        if s[i] == 'T':
            ts.append(i)
    ts.append(len(s))
    nums = map(lambda i: ts[i + 1] - ts[i] - 1, range(len(ts) - 1))
    x_nums = []
    y_nums = []
    for i in range(len(nums)):
        if i % 2 == 0:
            y_nums.append(nums[i])
        else:
            x_nums.append(nums[i])
    return possible(fx, x_nums) and possible(fy, y_nums)

print 'Yes' if solve(s, fx, fy) else 'No'

Solution (Python):
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")

Solution (Python):
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')

Solution (Python):
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')

Solution (Python):
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')

Solution (Python):
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')

Solution (Python):
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)

Solution (Python):
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")

Solution (Python):
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")

Solution (Python):
import sys
S = input()
x,y = 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')
    sys.exit()

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

Solution (Python):

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

Solution (Python):
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")

Solution (Python):
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
  elif s[0]=="F":
    s.pop(0)
    step+=1
    if len(s)==0:
      if flag==-1: updw+=[step]
      else: side+=[step]
  else: break
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")

Solution (Python):

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()
        nN.update([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")

Solution (Python):
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")