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 collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



s = S()
x, y = LI()
components = [len(i) for i in s.split('T')]
initial_x = components[0]
components = components[1:]
y_component = [j for j in components[::2] if j]
x_component = [j for j in components[1::2] if j]
x_len = len(x_component)
y_len = len(y_component)
x_D = defaultdict(int)
y_D = defaultdict(int)


x_D[initial_x] = 1
for i in range(x_len):
    nxt_x_D = defaultdict(int)
    for pos in x_D.keys():
        nxt_x_D[pos + x_component[i]] = nxt_x_D[pos - x_component[i]] = 1
    x_D = nxt_x_D


y_D[0] = 1
for i in range(y_len):
    nxt_y_D = defaultdict(int)
    for pos in y_D.keys():
        nxt_y_D[pos + y_component[i]] = nxt_y_D[pos - y_component[i]] = 1
    y_D = nxt_y_D



if x_D[x] and y_D[y]:
    print('Yes')
else:
    print('No')

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
n = len(s)
x,y = LI()
lst = []
tmp = 0
for i in range(n):
    if s[i] == 'T':
        lst.append(tmp)
        tmp = 0
    else:
        tmp += 1
if s[-1] != 'T':
    lst.append(tmp)
m = len(lst)
dpx = defaultdict(int)
dpy = defaultdict(int)
dpx[0] = True
dpy[0] = True
for i in range(m):
    if i % 2:
        tmp = defaultdict(int)
        for k in dpy.keys():
            tmp[k + lst[i]] = True
            tmp[k - lst[i]] = True
        dpy = tmp
    else:
        tmp = defaultdict(int)
        if i == 0:
            for k in dpx.keys():
                tmp[k + lst[i]] = True
        else:
            for k in dpx.keys():
                tmp[k + lst[i]] = True
                tmp[k - lst[i]] = True
        dpx = tmp
if dpx[x] and dpy[y]:
    print('Yes')
else:
    print('No')

Solution (Python):
s=input()
x,y=map(int,input().split())

l=[0]
for i in s:
    if i=="F":
        l[-1]+=1
    else:
        l.append(0)
lx=[0]
ly=[0]
for i in range(len(l)):
    if i==0:
        continue
    if i%2==0:
        lx.append(l[i])
    else:
        ly.append(l[i])

q=[l[0]]
for i in lx:
    ll=set()
    for j in q:
        ll.add(j+i)
        ll.add(j-i)
    q=list(ll)
if x not in set(q):
    print("No")
    exit()

q=[0]
for i in ly:
    ll=set()
    for j in q:
        ll.add(j+i)
        ll.add(j-i)
    q=list(ll)
if y in set(q):
    print("Yes")
else:
    print("No")

Solution (Python):
s=input()
x,y=map(int,input().split())

l=[0]
for i in s:
    if i=="F":
        l[-1]+=1
    else:
        l.append(0)
lx=[0]
ly=[0]
for i in range(len(l)):
    if i==0:
        continue
    if i%2==0:
        lx.append(l[i])
    else:
        ly.append(l[i])

q=[l[0]]
for i in lx:
    ll=set()
    for j in q:
        ll.add(j+i)
        ll.add(j-i)
    q=list(ll)
if x not in set(q):
    print("No")
    exit()

q=[0]
for i in ly:
    ll=set()
    for j in q:
        ll.add(j+i)
        ll.add(j-i)
    q=list(ll)
if y in set(q):
    print("Yes")
else:
    print("No")

Solution (Python):
s = input()
x, y = map(int,input().split())

s = s.split("T")
s = [len(e) for e in s]
a = []
b = []
for i, s in enumerate(s):
    if i % 2 == 0:
        a.append(s)
    else:
        b.append(s)

x -= a.pop(0)
ans = True

dpx = [[False] * (2*abs(x) + 1) for _ in range(len(a) + 1)]
dpx[0][abs(x)] = True

for i in range(1,len(a)+1):
    for j in range(2*abs(x) + 1):
        if j + a[i-1] < 2*abs(x) + 1:
            dpx[i][j] |= dpx[i-1][j+a[i-1]]
        if j - a[i-1] >= 0:
            dpx[i][j] |= dpx[i-1][j-a[i-1]]

ans &= dpx[len(a)][x+abs(x)]

dpy = [[False] * (2*abs(y) + 1) for _ in range(len(b) + 1)]
dpy[0][abs(y)] = True

for i in range(1, len(b) + 1):
    for j in range(2*abs(y) + 1):
        if j + b[i-1] < 2*abs(y) + 1:
            dpy[i][j] |= dpy[i-1][j+b[i-1]]
        if j - b[i-1] >= 0:
            dpy[i][j] |= dpy[i-1][j-b[i-1]]

ans &= dpy[len(b)][y+abs(y)]

if ans:
    print("Yes")
else:
    print("No")

Solution (Python):
import sys
input = sys.stdin.readline

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

    Xs = []
    Ys = []
    line = True
    first = True
    x0, y0 = 0, 0
    a = 0
    for s in S:
        if s == 'F':
            a += 1
        else:
            if first:
                if a > 0:
                    x0 = a
                a = 0
                first = False
                line = False
                continue
            if a > 0:
                if line:
                    Xs.append(a)
                else:
                    Ys.append(a)
                a = 0
            if line:
                line = False
            else:
                line = True
    if a > 0:
        if line:
            Xs.append(a)
        else:
            Ys.append(a)

    Lx = sum(Xs)+x0
    dpx = [[False for _ in range(2*Lx+1)] for _ in range(len(Xs)+1)]
    dpx[0][x0+Lx] = True

    for i, x in enumerate(Xs):
        for j in range(2*Lx+1):
            if j+x <= 2*Lx:
                dpx[i+1][j+x] = dpx[i][j] or dpx[i+1][j+x]
            if j-x >= 0:
                dpx[i+1][j-x] = dpx[i][j] or dpx[i+1][j-x]

    Ly = sum(Ys)+y0
    dpy = [[False for _ in range(2*Ly+1)] for _ in range(len(Ys)+1)]
    dpy[0][y0+Ly] = True

    for i, y in enumerate(Ys):
        for j in range(2*Ly+1):
            if j+y <= 2*Ly:
                dpy[i+1][j+y] = dpy[i][j] or dpy[i+1][j+y]
            if j-y >= 0:
                dpy[i+1][j-y] = dpy[i][j] or dpy[i+1][j-y]
    
    if (not -Lx <= X <= Lx) or (not -Ly <= Y <= Ly): 
        print('No')
    elif dpx[-1][X+Lx] and dpy[-1][Y+Ly]:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()

Solution (Python):
s = input()
x, y = map(int, input().split())
n = len(s)

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    x -= 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1




ANS = [0, 0]
st_po = [0, 0]
go_po = [x, y]
for i in range(2):
    mid = sum(D[i]) + 5
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            aa = 0
            bb = 0
            if 0 <= k-dd <= len(DP[0])-1:
                aa = DP[j][k-dd]
            if 0 <= k+dd <= len(DP[0])-1:
                bb = DP[j][k+dd]

            DP[j+1][k] = int(aa or bb)

    if 0 <= go_po[i]+mid <= len(DP[0])-1:
        ANS[i] = DP[-1][go_po[i]+mid]
    
    
        


print("Yes" if ANS[0] and ANS[1] else "No")

Solution (Python):
s = input()
x, y = map(int, input().split())
l = s.split("T")

x -= len(l[0])
ys = []
xs = []
if len(l) == 1:
  if x == 0 and y == 0:
    print("Yes")
  else:
    print("No")
  exit(0)
for i in range(len(l)):
  if i == 0:
    continue
  if i % 2:
    ys.append(len(l[i]))
  else:
    xs.append(len(l[i]))





dpx = set()
dpx.add(0)
for i in range(len(xs)):
  nextset = set()
  for j in dpx:
    nextset.add(j + xs[i])
    nextset.add(j - xs[i])
  dpx = nextset
dpy = set()
dpy.add(0)
for i in range(len(ys)):
  nextset = set()
  for j in dpy:
    nextset.add(j + ys[i])
    nextset.add(j - ys[i])
  dpy = nextset
if x in dpx and y in dpy:
  print("Yes")
else:
  print("No")

Solution (Python):
s = input()
x,y = map(int,input().split())
 
X = []
Y = []
flag = 0
tmp = 0
for i in s:
    if i == "T":
        if flag == 0:
            if tmp != 0:
                X.append(tmp)
            flag = 1
            tmp = 0
        else:
            if tmp != 0:
                Y.append(tmp)
            flag = 0
            tmp = 0
    else:
        tmp += 1
if tmp != 0:
    if flag == 0:
        X.append(tmp)
    else:
        Y.append(tmp)

if s[0] !="T":
    tmpX = X[0]
    del X[0]
else:
    tmpX = 0

X = sorted(X)
Y = sorted(Y)
sumX = sum(X)
sumY = sum(Y)
tmpY = 0
 
ans = 0
 
if (x+sumX-tmpX)%2 == 1:
    ans = 1
else:
    mokuhyoX = (x+sumX-tmpX)//2
if (y+sumY-tmpY)%2 == 1:
    ans = 1
else:
    mokuhyoY = (y+sumY-tmpY)//2
if ans == 0:
	if mokuhyoX < 0 or mokuhyoY < 0:
	    ans = 1


if ans == 0:
    dpX = [[False]*(mokuhyoX+1) for _ in range(len(X)+1)]
    dpX[0][0] = True
    for i in range(len(X)):
        for j in range(mokuhyoX+1):
            dpX[i+1][j] = dpX[i+1][j] or dpX[i][j]
            if j >= X[i]:
                dpX[i+1][j] = dpX[i+1][j] or dpX[i][j-X[i]]
    
    

if ans == 0:
    dpY = [[False]*(mokuhyoY+1) for _ in range(len(Y)+1)]
    dpY[0][0] = True
    for i in range(len(Y)):
        for j in range(mokuhyoY+1):
            dpY[i+1][j] = dpY[i+1][j] or dpY[i][j]
            if j >= Y[i]:
                dpY[i+1][j] = dpY[i+1][j] or dpY[i][j-Y[i]]
 
if ans==0:
    if dpX[len(X)][mokuhyoX] == dpY[len(Y)][mokuhyoY] == True:
        ans = 0
    else:
        ans = 1
    
if ans == 1:
    print("No")
else:
    print("Yes")

Solution (Python):
s = input()
x,y = map(int,input().split())
wayx = []
wayy = []
pad = 15000
can_reachx = [False for i in range(pad*2+1)]
can_reachy = [False for i in range(pad*2+1)]


state = True
seq = 0
for c in s:
    if c == "T":
        if state:
            wayx.append(seq)
            seq = 0
            state = False
        else:
            wayy.append(seq)
            seq = 0
            state = True
    else:
        seq += 1


if state:
    wayx.append(seq)
    seq = 0
    state = False
else:
    wayy.append(seq)
    seq = 0
    state = True

can_reachx[pad+wayx[0]] = True
can_reachy[pad] = True

for i in range(1,len(wayx)):
    w = wayx[i]
    b = []
    for j in range(len(can_reachx)):
        if can_reachx[j]:
            if j+w <= pad*2:
                b.append(j+w)
            if j-w >= 0:
                b.append(j-w)
            can_reachx[j] = False
    for t in b:
        can_reachx[t] = True

for w in wayy:
    b = []
    for i in range(len(can_reachy)):
        if can_reachy[i]:
            if i+w <= pad*2:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
            can_reachy[i] = False
    for t in b:
        can_reachy[t] = True

if can_reachx[x+pad] and can_reachy[y+pad]:
    print("Yes")
else:
    print("No")

Solution (Python):
S = input()
X, Y = [int(_) for _ in input().split()]
V = [[0], [0]]
d = 0
f = 1
for s in S:
    if s == 'F':
        if f:
            X -= 1
        else:
            V[d][-1] += 1
    else:
        f = 0
        d = 1 - d
        if V[d][-1]:
            V[d] += [0]
V = [sorted(_) for _ in V]
xs = set()


def judge(diff, vs):
    se = set([0])
    for v in vs:
        sen = set()
        for s in se:
            sen.add(s + v)
            sen.add(s - v)
        se = sen
    if diff not in se:
        print('No')
        exit()


judge(X, V[0])
judge(Y, V[1])
print('Yes')

Solution (Python):
S = input()
X, Y = [int(_) for _ in input().split()]
V = [[0], [0]]
d = 0
f = 1
for s in S:
    if s == 'F':
        if f:
            X -= 1
        else:
            V[d][-1] += 1
    else:
        f = 0
        d = 1 - d
        if V[d][-1]:
            V[d] += [0]
V = [sorted(_) for _ in V]
xs = set()


def judge(diff, vs):
    se = set([0])
    for v in vs:
        sen = set()
        for s in se:
            sen.add(s + v)
            sen.add(s - v)
        se = sen
    if diff not in se:
        print('No')
        exit()


judge(X, V[0])
judge(Y, V[1])
print('Yes')

Solution (Python):
s = input()
x, y = map(int, input().split())

count = [[], []]
now = 0
for f in s.split('T') :
    count[now].append(len(f))
    now ^= 1

def solve() :
    dp = set([count[0][0]])
    for c in count[0][1:] :
        if c == 0 :
            continue
        dp_ = set()
        for xi in dp :
            dp_.add(xi+c)
            dp_.add(xi-c)
        dp = dp_
    if not x in dp :
        return 'No'
    
    dp = set([0])
    for c in count[1] :
        if c == 0 :
            continue
        dp_ = set()
        for yi in dp :
            dp_.add(yi+c)
            dp_.add(yi-c)
        dp = dp_
    if not y in dp :
        return 'No'
    return 'Yes'

print(solve())

Solution (Python):
def cango(l,x):
    n=sum(l)
    if abs(x)>n:
        return False
    dp=[False]*(n+1)
    dp[0]=True
    for i in range(len(l)):
        dp1=[False]*(n+1)
        for j in range(n+1):
            if dp[j]:
                dp1[abs(j-l[i])]=True
                dp1[j+l[i]]=True
        for i in range(n+1):
            dp[i]=dp1[i]
    return dp[abs(x)]

l=eval("['"+input().replace('T',"','")+"']")
for i in range(len(l)):
    l[i]=len(l[i])
x,y=map(int,input().split())
if len(l)==1:
    print(['No','Yes'][x==l[0] and y==0])
elif len(l)==2:
    print(['No','Yes'][x==l[0] and abs(y)==abs(l[1])])
else:
    print(['No','Yes'][cango(l[2::2],x-l[0]) and cango(l[1::2],y)])

Solution (Python):
s = input()
xy = list(map(int,input().split()))
data = [[0],[0]]
direct = 0
for i in s:
    if i == "F":
        data[direct][-1] += 1
    else:
        direct ^= 1
        data[direct].append(0)
judge = [False, False]
for direct in range(2):
    set_now = set((data[direct][0],))
    for d in data[direct][1:]:
        s_next = set()
        for e in set_now:
            s_next.add(e+d)
            s_next.add(e-d)
        set_now = s_next

    if xy[direct] in set_now:
        judge[direct] = True

if judge[0] and judge[1]:
    print("Yes")
else:
    print("No")

Solution (Python):
from collections import deque


s = input()

x,y = map(int,input().split())

xlis = []
ylis = []

slis = deque()
for i in s:
    slis.append(i)


while True:
    if len(slis) > 0 and slis[0] == "F":
        x -= 1
        slis.popleft()
    else:
        break



direct = 0
tnum = 0
fnum = 0

while len(slis) > 0:

    nows = slis.popleft()

    if nows == "T":

        if tnum == 0 and fnum != 0:

            if  direct == 0:
                xlis.append(fnum)
            else:
                ylis.append(fnum)

            fnum = 0

        tnum += 1

    if nows == "F":

        direct = (direct + tnum) % 2
        tnum = 0
        fnum += 1

if fnum != 0:

    if direct == 0:
        xlis.append(fnum)
    else:
        ylis.append(fnum)




xdic = {}
ydic = {}


xdic[0] = 1
ydic[0] = 1


for i in xlis:

    nxdic = {}

    for j in xdic:
        nxdic[j + i] = 1
        nxdic[j - i] = 1

    xdic = nxdic.copy()

for i in ylis:

    nydic = {}

    for j in ydic:
        nydic[j + i] = 1
        nydic[j - i] = 1

    ydic = nydic.copy()

if x in xdic and y in ydic:
    print ("Yes")

else:
    print ("No")

Solution (Python):
s = list(map(len,input().split("T")))
x = s[::2]
y = s[1::2]
gx,gy = map(int,input().split())
if sum(x) < abs(gx) or sum(y) < abs(gy):
  print("No")
  exit(0)
dpx = [0]*(len(x)+1)
dpy = [0]*(len(y)+1)
dpx[0] = set([0])
dpy[0] = set([0])
for i in range(1,len(x)+1):
  s1 = set([v + x[i-1] for v in dpx[i-1]])
  s2 = set([v - x[i-1] for v in dpx[i-1]])
  if i == 1:
    dpx[i] = s1
  else:
    dpx[i] = s1|s2
for i in range(1,len(y)+1):
  s1 = set([v + y[i-1] for v in dpy[i-1]])
  s2 = set([v - y[i-1] for v in dpy[i-1]])
  dpy[i] = s1|s2
if gx in dpx[-1] and gy in dpy[-1]:
  print("Yes")
else:
  print("No")

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007


"""
a, b = LI()
print((a+b+1)//2)
"""


"""
a = S()
a = a[:-1]
b = S()
b = b[:-1]
a.sort()
b.sort(reverse=True)
if a < b:
    print("Yes")
else:
    print("No")
"""


"""
n = I()
a = LI()
a.sort()
seta = set(a)
ans = 0
for i in seta:
    x = bisect.bisect_right(a,i) - bisect.bisect_left(a,i)
    if x != 0 and x >= i:
        ans += x - i
    else:
        ans += x
print(ans)        
"""






s = S()
X, Y = LI()
dx = defaultdict(int)
dy = defaultdict(int)
i = 0
num = 0
lis = []
for i in range(len(s)):
    if s[i] == "T":
        lis.append(num)
        num = 0
    else:
        num += 1
if s[-1] == "F":
    lis.append(num)
dx[lis[0]] = True
dy[0] = True
for i in range(1, len(lis)):
    if not i % 2:
        ndx = defaultdict(int)
        for key, _ in dx.items():
            ndx[key + lis[i]] = True
            ndx[key - lis[i]] = True
        dx = ndx
    else:
        ndy = defaultdict(int)
        for key, _ in dy.items():
            ndy[key + lis[i]] = True
            ndy[key - lis[i]] = True
        dy = ndy
if dx[X] and dy[Y]:
    print("Yes")
else:
    print("No")

Solution (Python):
import numpy as np

def main():
    s = input().split("T")
    x, y = map(int, input().split())
    xs = []
    x -= len(s[0])
    for i in range(2, len(s), 2):
        tmp = len(s[i])
        if tmp != 0:
            xs.append(tmp)
    ys = []
    for i in range(1, len(s), 2):
        tmp = len(s[i])
        if tmp != 0:
            ys.append(tmp)
    
    sum_x = sum(xs)
    sum_y = sum(ys)
    x = abs(x)
    y = abs(y)
    if sum_x < x or sum_y < y:
        print("No")
    else:
        rest_x = sum_x - x
        rest_y = sum_y - y
        if rest_x&1 or rest_y&1:
            print("No")
        else:
            ok = True
            if rest_x > 0:
                dp = np.array([[False]*8001 for i in range(len(xs)+1)])
                dp[0][0] = True
                for i in range(1, len(xs)+1):
                    dp[i] = dp[i] | dp[i-1]
                    dp[i][xs[i-1]:] = dp[i-1][xs[i-1]:] | dp[i-1][:-xs[i-1]]
                    
                if not dp[-1][rest_x//2]:
                    ok = False
            if rest_y > 0:
                dp = np.array([[False]*8001 for i in range(len(ys)+1)])
                dp[0][0] = True
                for i in range(1, len(ys)+1):
                    dp[i] = dp[i] | dp[i-1]
                    dp[i][ys[i-1]:] = dp[i-1][ys[i-1]:] | dp[i-1][:-ys[i-1]]
                    
                if not dp[-1][rest_y//2]:
                    ok = False
            if ok:
                print("Yes")
            else:
                print("No")
                    

if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict as d
s=input()+"T"
x,y=map(int,input().split())
p=[[],[]]
c,e=0,0
for i in s:
    if i=="T":
        if e!=0:
            p[c].append(e)
            e=0
        c=(c+1)%2
    else:
        e+=1
def f(a,c,q):
    g=d(int)
    r=0
    if q!=0:
        if len(a)>0 and s[0]=="F":
            g[a[0]]=1
            r=1
        else:
            g[0]=1
    else:
        g[0]=1
    for j in a[r:]:
        t=d(int)
        for i,h in g.items():
            t[i-j]=1
            t[i+j]=1
        else:
            g=t
    return g[c]!=0
print("Yes" if f(p[0],x,1)*f(p[1],y,0)==1 else"No")

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7












































    

def can_reach(x_aim, default_pos, x_moves):  
    dp = set([default_pos])
    for i in x_moves:
        new_dp = []
        for j in dp:
            new_dp.append(j+i)
            new_dp.append(j-i)
        dp = set(new_dp)
    return x_aim in dp


def main(): 
    s = SI()
    x, y = LI()

    x_moves = []
    y_moves = []
    moving_x = True
    for i in s.split('T'):
        if moving_x:
            x_moves.append(len(i))
        else:
            y_moves.append(len(i))
        moving_x = not moving_x

    if can_reach(x, x_moves[0], x_moves[1:]) and can_reach(y, 0, y_moves):
        print('Yes')
    else:
        print('No')


main()

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7












































    

def can_reach(x_aim, default_pos, x_moves):  
    dp = set([default_pos])
    for i in x_moves:
        new_dp = []
        for j in dp:
            new_dp.append(j+i)
            new_dp.append(j-i)
        dp = set(new_dp)
    return x_aim in dp


def main(): 
    s = SI()
    x, y = LI()

    x_moves = []
    y_moves = []
    moving_x = True
    for i in s.split('T'):
        if moving_x:
            x_moves.append(len(i))
        else:
            y_moves.append(len(i))
        moving_x = not moving_x

    if can_reach(x, x_moves[0], x_moves[1:]) and can_reach(y, 0, y_moves):
        print('Yes')
    else:
        print('No')

main()

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7










def can_reach(x_aim, default_pos, x_moves):  
    for i in sorted(x_moves, reverse=True):
        if x_aim > default_pos:
            default_pos += i
        else:
            default_pos -= i
    if default_pos == x_aim:
        return True
    else:
        return False

def main(): 
    s = SI()
    x, y = LI()

    x_moves = []
    y_moves = []
    moving_x = True
    for i in s.split('T'):
        if moving_x:
            x_moves.append(len(i))
        else:
            y_moves.append(len(i))
        moving_x = not moving_x

    if can_reach(x, x_moves[0], x_moves[1:]) and can_reach(y, 0, y_moves):
        print('Yes')
    else:
        print('No')


main()

Solution (Python):
s = input()
X, Y = map(int, input().split())
fs = s.split("T")
nsx = list(map(len, fs[0::2]))
nsy = list(map(len, fs[1::2]))
ssx = []
ssx.append({ 0 })
ssx.append({ nsx[0] })
for i in range(1, len(nsx)):
  s = ssx[i]
  n = nsx[i]
  s2 = set()
  for x in s:
    s2.add(x+n)
    s2.add(x-n)
  ssx.append(s2)

ssy = [{ 0 }]
for i in range(0, len(nsy)):
  s = ssy[i]
  n = nsy[i]
  s2 = set()
  for y in s:
    s2.add(y+n)
    s2.add(y-n)
  ssy.append(s2)

if X in ssx[-1] and Y in ssy[-1]:
  print("Yes")
else:
  print("No")

Solution (Python):
s = input()
x, y = map(int, input().split())

def cul(x_axis,x):
    dic={0:1}
    for i in range(len(x_axis)):
        tmp={}
        for j in dic:
            tmp[j+x_axis[i]]=1
            tmp[j-x_axis[i]]=1
        dic=tmp
    if x in dic: return True
    else: return False

s_split = [len(item) for item in s.split("T")]

x_axis = s_split[0::2]
y_axis = s_split[1::2]

if s[0]=="F": x=abs(x-x_axis.pop(0))
y=abs(y)

print("Yes" if cul(x_axis,x) and cul(y_axis,y) else "No")

Solution (Python):
s=input()
xy=list(map(int,input().split()))
p=[[0],[0]]
i=0
for c in s:
    if c=='F':
        p[i][-1]+=1
    else:
        i^=1
        p[i].append(0)
a=[1,1]
for i in range(2):
    s0=set((p[i][0],))
    for j in range(1,len(p[i])):
        s1=set()
        for e in s0:
            s1.add(e+p[i][j])
            s1.add(e-p[i][j])
        s0=s1
    if xy[i] not in s0:
        a[i]=0
print(['No','Yes'][all(a)])

Solution (Python):
s = input()
x, y = [ int(v) for v in input().split() ]

f_length_list = list(map(len,s.split("T")))

x_point_set = set([0])
y_point_set = set([0])

for i, v in enumerate(f_length_list):
    new_point_set = set([])
    if i % 2 == 0:
        if i == 0:
            new_point_set.add(v)
        else:
            for j in x_point_set:
                new_point_set.add(j+v)
                new_point_set.add(j-v)
        x_point_set = new_point_set

    elif i % 2 != 0:
        for j in y_point_set:
            new_point_set.add(j+v)
            new_point_set.add(j-v)
        y_point_set = new_point_set

if x in x_point_set and y in y_point_set:
    ans = "Yes"
else:
    ans = "No"
print(ans)

Solution (Python):

def rleify(s):
    if not len(s):
        return []
    i = 0
    rle = []
    for j in range(len(s) + 1):
        if j == len(s) or s[i] != s[j]:
            rle.append((s[i], j - i))
            i = j
    return rle


s = input()
X, Y = map(int, input().split())
rle = rleify(s)
if rle[0][0] == "F":
    X -= rle[0][1]
    rle = rle[1:]
S = []
P = []
iss = True
for c, n in rle:
    if c == "T":
        if n % 2 == 1:
            iss = not iss
    else:
        if iss:
            S.append(n)
        else:
            P.append(n)

cand = {0}
for n in S:
    ncand = set()
    for c in cand:
        ncand.add(c - n)
        ncand.add(c + n)
    cand = ncand
if X not in cand:
    print("No")
    exit()

cand = {0}
for n in P:
    ncand = set()
    for c in cand:
        ncand.add(c - n)
        ncand.add(c + n)
    cand = ncand
if Y not in cand:
    print("No")
    exit()
print("Yes")

Solution (Python):

def rleify(s):
    if not len(s):
        return []
    i = 0
    rle = []
    for j in range(len(s) + 1):
        if j == len(s) or s[i] != s[j]:
            rle.append((s[i], j - i))
            i = j
    return rle


s = input()
X, Y = map(int, input().split())
rle = rleify(s)
if rle[0][0] == "F":
    X -= rle[0][1]
    rle = rle[1:]
S = []
P = []
iss = True
for c, n in rle:
    if c == "T":
        if n % 2 == 1:
            iss = not iss
    else:
        if iss:
            S.append(n)
        else:
            P.append(n)

cand = {0}
for n in S:
    ncand = set()
    for c in cand:
        ncand.add(c - n)
        ncand.add(c + n)
    cand = ncand
if X not in cand:
    print("No")
    exit()

cand = {0}
for n in P:
    ncand = set()
    for c in cand:
        ncand.add(c - n)
        ncand.add(c + n)
    cand = ncand
if Y not in cand:
    print("No")
    exit()
print("Yes")

Solution (Python):
def isReach( goal, move, is_x):
    msum = sum(move)
    m = len(move)

    if msum < abs(goal):
        return False

    dp = [[False for _ in range(msum*2+1)] for _ in range(m+1)]
    dp[0][0] = True
    
    for i in range(m):
        for j in range(-msum,msum+1):
            if i == 0 and dp[i][j] and is_x:
                dp[i+1][j+move[i]] = True
            elif dp[i][j]:
                dp[i+1][j-move[i]] = True
                dp[i+1][j+move[i]] = True
    
    return dp[m][goal]


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

move_dist = [len(move) for move in s]
x_move = move_dist[0::2]
y_move = move_dist[1::2]

if isReach(x,x_move,True) and isReach(y,y_move,False):
    print('Yes')
else:
    print('No')

Solution (Python):
s=input()+'T'
x,y=map(int,input().split())
if 'T' in s:
  pos=s.index('T')
  x-=pos
  s=s[pos+1:]
arr=s.split('T')
xarr=[]
yarr=[]
for i in range(len(arr)):
  l=len(arr[i])
  if l==0:
    continue
  if i%2==0:
    yarr.append(l)
  else:
    xarr.append(l)
xarr=sorted(xarr)
yarr=sorted(yarr)
xsums=[0]
for val in xarr:
  xsums.append(xsums[-1]+val)
ysums=[0]
for val in yarr:
  ysums.append(ysums[-1]+val)
if len(xarr)!=0:
  xmax=xarr[-1]
  xsum=xsums[-1]
else:
  xmax=0
  xsum=0
if len(yarr)!=0:
  ymax=yarr[-1]
  ysum=ysums[-1]
else:
  ymax=0
  ysum=0
x+=xsum
y+=ysum
if x%2==1 or y%2==1:
  print('No')
else:
  xdp=[0]*10000
  xdp[0]=1
  for j in range(len(xarr)):
    val=xarr[j]
    for i in range(xsums[j]+val+1,-1,-1):
      if i-val<0:
        break
      if xdp[i-val]==1:
        xdp[i]=1
  ydp=[0]*10000
  ydp[0]=1
  for j in range(len(yarr)):
    val=yarr[j]
    for i in range(ysums[j]+val+1,-1,-1):
      if i-val<0:
        break
      if ydp[i-val]==1:
        ydp[i]=1
  if xdp[x//2]==0:
    print('No')
  else:
    if ydp[y//2]==0:
      print('No')
    else:
      print('Yes')

Solution (Python):
s=input()+'T'
x,y=map(int,input().split())
if 'T' in s:
  pos=s.index('T')
  x-=pos
  s=s[pos+1:]
arr=s.split('T')
xarr=[]
yarr=[]
for i in range(len(arr)):
  l=len(arr[i])
  if l==0:
    continue
  if i%2==0:
    yarr.append(l)
  else:
    xarr.append(l)
x+=sum(xarr)
y+=sum(yarr)
if x%2==1 or y%2==1:
  print('No')
else:
  
  xdp=[0]*8005
  xdp[0]=1
  for val in xarr:
    for i in range(8004,-1,-1):
      if i-val<0:
        break
      if xdp[i-val]==1:
        xdp[i]=1
  ydp=[0]*8005
  ydp[0]=1
  for val in yarr:
    for i in range(8004,-1,-1):
      if i-val<0:
        break
      if ydp[i-val]==1:
        ydp[i]=1
  if xdp[x//2]==0:
    print('No')
  else:
    if ydp[y//2]==0:
      print('No')
    else:
      print('Yes')