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 itertools import groupby


s=input()
x,y=map(int,input().split())
data=[s[i] for i in range(0,len(s))]
data=groupby(data)
LR=[]
UD=[]
point='LR'
flag=0
checkx=2**8000
for key,group in data:
    g=len(list(group))
    if key=='F':
        if flag==0:
            checkx=checkx<<g
            flag=1
        else:
            if point=='LR':
                LR.append(g)
            else:
                UD.append(g)
    else:
        if g%2==1:
            if point=='LR':
                point='UD'
            else:
                point='LR'
        flag=1


for i in range(0,len(LR)):
    checkx=(checkx<<LR[i])|(checkx>>LR[i])

checky=2**8000
for i in range(0,len(UD)):
    checky=(checky<<UD[i])|(checky>>UD[i])


if checkx>>(x+8000) &1==1 and checky>>(y+8000) &1==1:
    print('Yes')
else:
    print('No')

Solution (Python):


import io
import sys
import math

array = list(map(len, input().split('T')))
nim, mike = map(int, input().split())

tom = [set([array[0]]), set([0])]

for i in range(1, len(array)):
    nxt = set()
    for j in tom[i % 2]:
        nxt.add(j + array[i])
        nxt.add(j - array[i])
    tom[i % 2] = nxt

if nim in tom[0] and mike in tom[1]:
    print("Yes")
else:
    print("No")

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product

def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=input()
x,y=map(int,input().split())
tate,yoko=[],[]
kaisi=0
tmp=0
flag=1
for i in range(len(s)):
    if s[i]=="F":
        tmp+=1
    elif s[i]=="T":
        if kaisi==0:
            kaisi=1
            x-=tmp
        elif flag==0:
            flag=1
            yoko.append(tmp)
        else:
            flag=0
            tate.append(tmp)
        tmp=0


if kaisi==0:
    kaisi=1
    x-=tmp
elif flag==0:
    flag=1
    yoko.append(tmp)
else:
    flag=0
    tate.append(tmp)









if abs(x)>sum(yoko) or abs(y)>sum(tate):
    print("No")
    quit()
yokolst=[[0]*(sum(yoko)*2+1) for i in range(len(yoko)+1)]
tatelst=[[0]*(sum(tate)*2+1) for i in range(len(tate)+1)]
yokolst[0][sum(yoko)]=1
tatelst[0][sum(tate)]=1


for i in range(len(tate)):
    for j in range(len(tatelst[0])):
        if tatelst[i][j]==1:
            tatelst[i+1][j+tate[i]]=1
            tatelst[i+1][j-tate[i]]=1


for i in range(len(yoko)):
    for j in range(len(yokolst[0])):
        if yokolst[i][j]==1:
            yokolst[i+1][j+yoko[i]]=1
            yokolst[i+1][j-yoko[i]]=1





if tatelst[-1][sum(tate)+y]==1 and yokolst[-1][sum(yoko)+x]==1:
    print("Yes")
else:
    print("No")

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product

def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=input()
x,y=map(int,input().split())
tate,yoko=[],[]
kaisi=0
tmp=0
flag=1
for i in range(len(s)):
    if s[i]=="F":
        tmp+=1
    elif s[i]=="T":
        if kaisi==0:
            kaisi=1
            x-=tmp
        elif flag==0:
            flag=1
            yoko.append(tmp)
        else:
            flag=0
            tate.append(tmp)
        tmp=0


if kaisi==0:
    kaisi=1
    x-=tmp
elif flag==0:
    flag=1
    yoko.append(tmp)
else:
    flag=0
    tate.append(tmp)

if sum(yoko)==0 and sum(tate)==0:
    if x==0 and y==0:
        print("Yes")
    else:
        print("No")
    quit()


if abs(x)>sum(yoko) or abs(y)>sum(tate):
    print("No")
    quit()
yokolst=[[0]*(sum(yoko)*2+1) for i in range(len(yoko)+1)]
tatelst=[[0]*(sum(tate)*2+1) for i in range(len(tate)+1)]
yokolst[0][sum(yoko)]=1
tatelst[0][sum(tate)]=1


for i in range(len(tate)):
    for j in range(len(tatelst[0])):
        if tatelst[i][j]==1:
            tatelst[i+1][j+tate[i]]=1
            tatelst[i+1][j-tate[i]]=1


for i in range(len(yoko)):
    for j in range(len(yokolst[0])):
        if yokolst[i][j]==1:
            yokolst[i+1][j+yoko[i]]=1
            yokolst[i+1][j-yoko[i]]=1





if tatelst[-1][sum(tate)+y]==1 and yokolst[-1][sum(yoko)+x]==1:
    print("Yes")
else:
    print("No")

Solution (Python):
from collections import deque
import sys
sys.setrecursionlimit(10**8)

def dp(dp_l,i,N,xs,cum,now):
    if i == N:
        if now == 0:
            return True
        return False
    if abs(now) > cum[i]:
        return False
    if dp_l[i][abs(now)] != -1:
        return dp_l[i][abs(now)]
    dp_l[i][abs(now)] = dp(dp_l,i+1,N,xs,cum,now+xs[i]) or dp(dp_l,i+1,N,xs,cum,now-xs[i])
    return dp_l[i][abs(now)]

def check():
    S = input()
    x, y = map(int, input().split())
    fs = list(map(len,S.split('T')))
    if len(fs)<3:
        if x != fs[0]:
            return False
        if len(fs)==1:
            if y == 0:
                return True
            else:
                return False
        if y != fs[1] and y != -fs[1]:
            return False
        return True
    xs = fs[2::2]
    ys = fs[1::2]
    xs.sort(reverse = True)
    N = len(xs)
    M = len(ys)
    cum = [0]*(N+1)
    for i in range(N-1,-1,-1):
        cum[i] = cum[i+1]+xs[i]
    dp_l = [[-1]*(cum[0]+1) for _ in range(N)]
    if not dp(dp_l,0,N,xs,cum,fs[0]-x):
        return False
    ys.sort(reverse = True)
    cum = [ys[-1]]*(M+1)
    for i in range(M-1,-1,-1):
        cum[i] = cum[i+1]+ys[i]
    dp_l = [[-1]*(cum[0]+1) for _ in range(M)]
    if not dp(dp_l,0,M,ys,cum,-y):
        return False
    return True
if check():
    print('Yes')
else:
    print('No')

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

s = input().rstrip()
x, y = [int(x) for x in input().split()]

horizontal = []
vertical = []

switch = 1
distance = 0

for i in range(len(s)):
    if s[i] == "F":
        distance += 1
    elif switch:
        horizontal.append(distance)
        distance = 0
        switch ^= 1
    else:
        vertical.append(distance)
        distance = 0
        switch ^= 1

if switch:
    horizontal.append(distance)
else:
    vertical.append(distance)

dp_x = [[0] * (2 * sum(horizontal) + 1) for _ in range(len(horizontal) + 1)]
dp_y = [[0] * (2 * sum(vertical) + 1) for _ in range(len(vertical) + 1)]

sx = sum(horizontal)
sy = sum(vertical)

if not (-sx <= x <= sx and -sy <= y <= sy):
    print("No")
    exit()

dp_x[0][0 + sx] = 1
dp_y[0][0 + sy] = 1
dp_x[1][horizontal[0] + sx] = 1

for i in range(2, len(horizontal) + 1):
    x_ = horizontal[i - 1]
    for j in range(-sx, sx + 1):
        if -sx <= j - x_ <= sx: 
            dp_x[i][j + sx] = max(dp_x[i][j + sx], dp_x[i - 1][j - x_ + sx])
        if -sx <= j + x_ <= sx:
            dp_x[i][j + sx] = max(dp_x[i][j + sx], dp_x[i - 1][j + x_ + sx])


for i in range(1, len(vertical) + 1):
    y_ = vertical[i - 1]
    for j in range(-sy, sy + 1):
        if -sy <= j - y_ <= sy: 
            dp_y[i][j + sy] = max(dp_y[i][j + sy], dp_y[i - 1][j - y_ + sy])
        if -sy <= j + y_ <= sy:
            dp_y[i][j + sy] = max(dp_y[i][j + sy], dp_y[i - 1][j + y_ + sy])

if dp_x[-1][x + sx] and dp_y[-1][y + sy]:
    print("Yes")
else:
    print("No")

Solution (Python):
import itertools

s = input()
x,y = map(int,input().split())
d = [len(fs) for fs in s.split('T')]
x -= d[0]
dx = d[2::2]
dy = d[1::2]

def check(d,x):
    set_ = set([0])
    for dx in d:
        set_ = {a+b for a,b in itertools.product(set_,[dx,-dx])}
    return x in set_
if check(dx,x) and check(dy,y):
    print('Yes')
else:
    print('No')

Solution (Python):
from collections import deque

S = input()
X, Y = map(int, input().split())
F = [deque() for _ in (0, 1)]

i = 0
tmp = 0
for s in S:
    if s == 'F':
        tmp += 1
    else:
        F[i].append(tmp)
        i = (i + 1) % 2
        tmp = 0
if tmp:
    F[i].append(tmp)

first = F[0].popleft()

T = [{first}, {0}]
for i in range(2):
    for j in F[i]:
        T[i] = {k - j for k in T[i]} | {k + j for k in T[i]}
if X in T[0] and Y in T[1]:
    print('Yes')
else:
    print('No')

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

    s = input().rstrip()
    x,y = map(int, input().split())
    f = s.split('T')
    dx_list = list(map(len, f[::2]))
    dy_list = list(map(len, f[1::2]))
    
    nx = dx_list.pop(0)
    ny = 0

    dx_list.sort(reverse=True)
    dy_list.sort(reverse=True)

    for dx in dx_list:
        if x >= nx:
            nx += dx
        else:
            nx -= dx
    for dy in dy_list:
        if y >= ny:
            ny += dy
        else:
            ny -= dy

    if nx == x and ny == y:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    s = input().rstrip() + 'T'
    x,y = map(int, input().split())
    
    l = []
    susumu = 0
    for i in range(len(s)):
        if s[i] == 'T':
            l.append(susumu)
            susumu = 0
        else:
            susumu += 1
    b = len(l)
    dp = [[0]*16001 for _ in range(3)]
    dp[0][8000] = 1
    dp[1][8000] = 1
    for i in range(b):
        if i==0:
            dp[2][8000+l[i]] = 1
        elif i%2 == 0:
            for j in range(16000):
                if dp[0][j]:
                    dp[2][j-l[i]] = 1
                    dp[2][j+l[i]] = 1
        elif i%2 == 1:
            for j in range(16000):
                if dp[0][j]:
                    dp[2][j-l[i]] = 1
                    dp[2][j+l[i]] = 1
        dp = dp[1:] + [[0]*16000]
    if b%2 == 0:
        if dp[0][x+8000] == 1 and dp[1][y+8000] == 1:
            print('Yes')
        else:
            print('No')
    else:
        if dp[1][x+8000] == 1 and dp[0][y+8000] == 1:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
def main():
    order = [len(el) for el in list(map(str, input().rstrip().split("T")))]
    x, y = map(int, input().split())
    order_x = order[2::2]
    order_y = order[1::2]
    L_x, L_y = len(order_x), len(order_y)
    n = 10000
    dp_x = [np.zeros(2*n, dtype=np.bool) for _ in range(L_x + 1)]
    dp_y = [np.zeros(2*n, dtype=np.bool) for _ in range(L_y + 1)]
    dp_x[0][n + order[0]] = True
    dp_y[0][n] = True
    for i, d in enumerate(order_x):
        dp_x[i+1][d:] |= dp_x[i][:2*n-d]
        dp_x[i+1][:2*n-d] |= dp_x[i][d:]
    for i, d in enumerate(order_y):
        dp_y[i+1][d:] |= dp_y[i][:2*n-d]
        dp_y[i+1][:2*n-d] |= dp_y[i][d:]
    if dp_x[L_x][n + x] and dp_y[L_y][n + y]:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

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

    dx = []
    dy = []
    dir = 0
    cnt = 0
    for i in range(n):
        if s[i] == 'F':
            cnt += 1
        else:
            if dir%2 == 0:
                dx.append(cnt)
                cnt = 0
                dir += 1
            else:
                dy.append(cnt)
                cnt = 0
                dir += 1
    else:
        if dir%2 == 0:
            dx.append(cnt)
        else:
            dy.append(cnt)

    dpx = [0]*(len(dx)+1)
    dpy = [0]*(len(dy)+1)

    import numpy as np
    D = 2*n+1
    dpx[0] = np.zeros(D, np.bool)
    dpy[0] = np.zeros(D, np.bool)
    dpx[0][n] = 1
    dpy[0][n] = 1

    for i in range(len(dx)):
        d = dx[i]
        if i == 0:
            b = np.zeros(D, np.bool)
            b[d:] |= dpx[i][:D-d]
        else:
            b = np.zeros(D, np.bool)
            b[d:] |= dpx[i][:D-d]
            b[:D-d] |= dpx[i][d:]
        dpx[i+1] = b

    for i in range(len(dy)):
        d = dy[i]
        b = np.zeros(D, np.bool)
        b[d:] |= dpy[i][:D-d]
        b[:D-d] |= dpy[i][d:]
        dpy[i+1] = b

    if dpx[-1][n+x] and dpy[-1][n+y]:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Solution (Python):

import sys
try:
    from typing import List
except ImportError:
    pass

YES = "Yes"  
NO = "No"  


def solve(s: str, x: int, y: int):
    try:
        k = s.index("T")
    except ValueError:
        k = len(s)
    x -= k
    s = s[k:]
    xs = []
    ys = []
    d = 0
    v = 0
    for c in s:
        if c == "T":
            if v != 0:
                if d == 0:
                    xs.append(v)
                else:
                    ys.append(v)
            d = 1 - d
            v = 0
        else:
            v += 1
    if v != 0:
        if d == 0:
            xs.append(v)
        else:
            ys.append(v)
    mx = sum(xs)
    dpx = [0] * (mx + 1)
    dpx[0] = 1
    for xi in xs:
        for j in reversed(range(xi, len(dpx))):
            dpx[j] |= dpx[j - xi]
    my = sum(ys)
    dpy = [0] * (my + 1)
    dpy[0] = 1
    for yi in ys:
        for j in reversed(range(yi, len(dpy))):
            dpy[j] |= dpy[j - yi]
    if (
        -mx <= x <= mx and (mx - x) % 2 == 0 and dpx[(mx - x) // 2] and
        -my <= y <= my and (my - y) % 2 == 0 and dpy[(my - y) // 2]
    ):
        print(YES)
    else:
        print(NO)



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  
    x = int(next(tokens))  
    y = int(next(tokens))  
    solve(s, x, y)


if __name__ == '__main__':
    main()

Solution (Python):
s=input()
x,y=map(int,input().split())
XY=[[]for i in range(2)]
a=0
b=0
for i in range(len(s)):
  if s[i]=="T":
    XY[b].append(a)
    a=0
    b=(b+1)%2
  else:
    a=a+1
XY[b].append(a)
xx=sum(XY[0])
yy=sum(XY[1])
dpx=[[0]*(2*xx+5) for i in range(len(XY[0])+1)]
dpy=[[0]*(2*yy+5) for i in range(len(XY[1])+1)]
dpx[1][xx+XY[0][0]+2]=1
for i in range(1,len(XY[0])):
  for j in range(2*xx+5):
    if dpx[i][j]==1:
      dpx[i+1][j-XY[0][i]]=1
      dpx[i+1][j+XY[0][i]]=1
dpy[0][yy+2]=1
for i in range(len(XY[1])):
  for j in range(2*yy+5):
    if dpy[i][j]==1:
      dpy[i+1][j-XY[1][i]]=1
      dpy[i+1][j+XY[1][i]]=1
if x+xx+2<0 or 2*xx+4<x+xx+2 or y+yy+2<0 or 2*yy+4<y+yy+2:
  print("No")
  exit()
if dpx[-1][x+xx+2]==1 and dpy[-1][y+yy+2]==1:
  print("Yes")
else:
  print("No")

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

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


def main():

    ss = list(input())[:-1]

    ss = s(ss)

    n = len(ss)

    x,y = m()

    x += 8000

    y += 8000

    dpx = set([8000])

    dpy = set([8000])

    ro = 0

    for i in range(1,n+1):
        pop = ss[i-1]
        if pop[0] == "T":
            if pop[1] % 2 == 1:
                ro ^= 1
        else:
            if i == 1:
                dpx = set([8000+pop[1]])
            else:
                if ro == 0:
                    ch = set()
                    for num in dpx:
                        if num + pop[1] <= 16000:
                            ch.add(num + pop[1])    
                        if num - pop[1] >= 0:
                            ch.add(num - pop[1])
                        dpx = ch
                else:
                    ch = set()
                    for num in dpy:
                        if num + pop[1] <= 16000:
                            ch.add(num + pop[1])
                        if num - pop[1] >= 0:
                            ch.add(num - pop[1])
                        dpy = ch

    if x in dpx and y in dpy:
        print("Yes")
    else:
        print("No")

            


if __name__ == "__main__":
    main()

Solution (Python):
str = input()
x,y = map(int,input().split())
dx,dy = 0,0

fn = [len(n) for n in str.split("T")]
dir = [[],[]]

for i in range(len(fn)):
  dir[i%2].append(fn[i])

xdir = dir[0]
ydir = dir[1]

dx = xdir.pop(0)
xdir.sort()
while xdir != []:
  if dx < x:
    dx += xdir.pop()
  else:
    dx -= xdir.pop()
    
ydir.sort()
while ydir != []:
  if dy < y:
    dy += ydir.pop()
  else:
    dy -= ydir.pop()

if dx == x and dy == y:
  print("Yes")
else:
  print("No")

Solution (Python):


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

if "T" in s:
    pass
else:
    if X==len(s) and Y==0:
        print("Yes")
    else:
        print("No")
    exit()


way=[[],[]]

switch=0
judge=True

lx=[]
ly=[0]
temp=0
for item in s:
    if item == "T":
        if judge:
            judge=False
            lx.append(temp)
        else:
            way[switch].append(temp)
        temp=0
        switch^=1
    else:
        temp+=1
way[switch].append(temp)



for x in way[0]:
    temp_x=[]
    for item in lx:
        temp_x.append(item+x)
        temp_x.append(item-x)
    lx=temp_x[:]
    lx=list(set(lx))


for y in way[1]:
    temp_y=[]
    for item in ly:
        temp_y.append(item+y)
        temp_y.append(item-y)
    ly=temp_y[:]
    ly=list(set(ly))


if (X in lx) and (Y in ly):
    print("Yes")
else:
    print("No")

Solution (Python):

s = input()
x, y = map(int, input().split())
xgo, ygo = [], []

cnt = 0
flg = True
check = True if s[0] == 'F' else False
for i in range(len(s)):
    if s[i] == 'T':
        if flg and cnt > 0:
            xgo.append(cnt)
        elif cnt > 0:
            ygo.append(cnt)
        cnt = 0
        flg = (flg + 1) % 2
    else:
        cnt += 1

if flg and cnt > 0:
    xgo.append(cnt)
elif cnt > 0:
    ygo.append(cnt)

flg1, flg2 = len(xgo)==0, len(ygo)==0

sum_x, sum_y = sum(xgo), sum(ygo)
dp1 = [[False for _ in range(2*sum_x+1)] for _ in range(len(xgo)+1)]
dp2 = [[False for _ in range(2*sum_y+1)] for _ in range(len(ygo)+1)]

if check:
    dp1[1][sum_x+xgo[0]] = True
    for i in range(2, len(xgo)+1):
        for j in range(-sum_x, sum_x+1):
            if 0 <= j+sum_x-xgo[i-1] <= 2*sum_x:
                if dp1[i-1][j+sum_x-xgo[i-1]]:
                    dp1[i][j+sum_x] = True
            if 0 <= j+sum_x+xgo[i-1] <= 2*sum_x:
                if dp1[i-1][j+sum_x+xgo[i-1]]:
                    dp1[i][j+sum_x] = True
else:
    dp1[0][sum_x] = True
    for i in range(1, len(xgo)+1):
        for j in range(-sum_x, sum_x+1):
            if 0 <= j+sum_x-xgo[i-1] <= 2*sum_x:
                if dp1[i-1][j+sum_x-xgo[i-1]]:
                    dp1[i][j+sum_x] = True
            if 0 <= j+sum_x+xgo[i-1] <= 2*sum_x:
                if dp1[i-1][j+sum_x+xgo[i-1]]:
                    dp1[i][j+sum_x] = True

dp2[0][sum_y] = True
for i in range(1, len(ygo)+1):
    for j in range(-sum_y, sum_y+1):
        if 0 <= j+sum_y-ygo[i-1] <= 2*sum_y:
            if dp2[i-1][j+sum_y-ygo[i-1]]:
                dp2[i][j+sum_y] = True
        if 0 <= j+sum_y+ygo[i-1] <= 2*sum_y:
            if dp2[i-1][j+sum_y+ygo[i-1]]:
                dp2[i][j+sum_y] = True
                
if flg1:
    flgx = (x == 0)
elif abs(x) > sum_x:
    flgx = False
else:
    flgx = dp1[len(xgo)][sum_x+x]
    
if flg2:
    flgy = (y == 0)
elif abs(y) >sum_y:
    flgy = False
else:
    flgy = dp2[len(ygo)][sum_y+y]
    
print('Yes' if flgx and flgy else 'No')

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

Solution (Python):
S = input().split('T')
x, y = map(int, input().split())

X = []
Y = []
for i, s in enumerate(S):
    if i % 2 == 0:
        X.append(len(s))
    else:
        Y.append(len(s))

if sum(X) < abs(x) or sum(Y) < abs(y):
    print('No')
    exit()

pos = set([X[0]])
for i in range(1, len(X)):
    d = X[i]
    npos = set()
    for p in pos:
        npos.add(p + d)
        npos.add(p - d)
    pos = npos
flag_x = x in pos

pos = set([0])
for i in range(len(Y)):
    d = Y[i]
    npos = set()
    for p in pos:
        npos.add(p + d)
        npos.add(p - d)
    pos = npos
flag_y = y in pos

if flag_x and flag_y:
    print('Yes')
else:
    print('No')

Solution (Python):
def main():
    from sys import exit
    s=input()
    x,y=map(int,input().split())

    def groupby(a):
        a2=[[a[0],1]]
        for i in range(1,len(a)):
            if a2[-1][0]==a[i]:
                a2[-1][1]+=1
            else:
                a2.append([a[i],1])
        return a2

    s=groupby(s)
    a,b=[],[]
    turn=True
    
    if s[0][0]=="F":
        x-=s[0][1]
        s.pop(0)
    for i in s:
        if i[0]=="F":
            if turn:
                a.append(-i[1])
            else:
                b.append(-i[1])
        elif i[1]%2==1:
            turn=not turn
    a.sort()
    b.sort()
    for i in a:
        x=abs(x)-abs(i)
    if x!=0:
        print("No")
        exit()
    for i in b:
        y=abs(y)-abs(i)
    if y!=0:
        print("No")
        exit()
    print("Yes")
main()

Solution (Python):
def main():
    from sys import exit
    s=input()
    x,y=map(int,input().split())

    def groupby(a):
        a2=[[a[0],1]]
        for i in range(1,len(a)):
            if a2[-1][0]==a[i]:
                a2[-1][1]+=1
            else:
                a2.append([a[i],1])
        return a2

    s=groupby(s)
    a,b=[],[]
    turn=True
    
    if s[0][0]=="F":
        x-=s[0][1]
        s.pop(0)
    for i in s:
        if i[0]=="F":
            if turn:
                a.append(-i[1])
            else:
                b.append(-i[1])
        elif i[1]%2==1:
            turn=not turn
    a.sort()
    b.sort()
    for i in a:
        x=abs(x)-abs(i)
    if x!=0:
        print("No")
        exit()
    for i in b:
        y=abs(y)-abs(i)
    if y!=0:
        print("No")
        exit()
    print("Yes")
main()

Solution (Python):
from sys import exit
s=input()
x,y=map(int,input().split())

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

s=groupby(s)
a,b=[],[]
turn=True

if s[0][0]=="F":
    x-=s[0][1]
    s.pop(0)
for i in s:
    if i[0]=="F":
        if turn:
            a.append(-i[1])
        else:
            b.append(-i[1])
    elif i[1]%2==1:
        turn=not turn
a.sort()
b.sort()
for i in a:
    x=abs(x)-abs(i)
if x!=0:
    print("No")
    exit()
for i in b:
    y=abs(y)-abs(i)
if y!=0:
    print("No")
    exit()
print("Yes")

Solution (Python):
from sys import exit
s=input()
x,y=map(int,input().split())

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

s=groupby(s)
a,b=[],[]
turn=True

if s[0][0]=="F":
    x-=s[0][1]
    s.pop(0)
for i in s:
    if i[0]=="F":
        if turn:
            a.append(-i[1])
        else:
            b.append(-i[1])
    elif i[1]%2==1:
        turn=not turn
a.sort()
b.sort()
for i in a:
    x=abs(x)-abs(i)
if x!=0:
    print("No")
    exit()
for i in b:
    y=abs(y)-abs(i)
if y!=0:
    print("No")
    exit()
print("Yes")

Solution (Python):
from sys import exit
s=input()
x,y=map(int,input().split())

t=[[s[0],1]]
for i in range(1,len(s)):
    if t[-1][0]==s[i]:
        t[-1][1]+=1
    else:
        t.append([s[i],1])

a,b=[],[]
turn=True

if t[0][0]=="F":
    x-=t[0][1]
    t.pop(0)
for i in t:
    if i[0]=="F":
        if turn:
            a.append(i[1])
        else:
            b.append(i[1])
    elif i[1]%2==1:
        turn=not turn
a.sort(reverse=True)
b.sort(reverse=True)
for i in a:
    x=abs(x)-abs(i)
if x!=0:
    print("No")
    exit()
for i in b:
    y=abs(y)-abs(i)
if y!=0:
    print("No")
    exit()
print("Yes")

Solution (Python):
from sys import exit
from itertools import groupby

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

s=[[h, len(list(g))] for h, g in groupby(s)]
a,b=[],[]
turn=True

if s[0][0]=="F":
    x-=s[0][1]
    s.pop(0)
for i in s:
    if i[0]=="F":
        if turn:
            a.append(i[1])
        else:
            b.append(i[1])
    elif i[1]%2==1:
        turn=not turn
a.sort(reverse=True)
b.sort(reverse=True)
for i in a:
    x=abs(x)-abs(i)
if x!=0:
    print("No")
    exit()
for i in b:
    y=abs(y)-abs(i)
if y!=0:
    print("No")
    exit()
print("Yes")

Solution (Python):
from sys import exit
s=input()
x,y=map(int,input().split())

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
s=groupby(s)
a,b=[],[]
turn=True

if s[0][0]=="F":
    x-=s[0][1]
    s.pop(0)
for i in s:
    if i[0]=="F":
        if turn:
            a.append(i[1])
        else:
            b.append(i[1])
    elif i[1]%2==1:
        turn=not turn
a.sort()
b.sort()
for i in a[::-1]:
    x=abs(x)-abs(i)
if x!=0:
    print("No")
    exit()
for i in b[::-1]:
    y=abs(y)-abs(i)
if y!=0:
    print("No")
    exit()
print("Yes")

Solution (Python):
from sys import exit
s=input()
xy=list(map(int,input().split()))

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
s=groupby(s)
ab=[[],[]]
turn=True

if s[0][0]=="F":
    xy[0]-=s[0][1]
    s.pop(0)
for i in s:
    if i[0]=="F":
        ab[not turn].append(i[1])
    elif i[1]%2==1:
        turn=not turn
for i in range(2):
    ab[i].sort(reverse=True)
    for j in ab[i]:
        xy[i]=abs(xy[i])-abs(j)
    if xy[i]!=0:
        print("No")
        exit()
print("Yes")

Solution (Python):
from sys import exit
s=input()
x,y=map(int,input().split())

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
s=groupby(s)
ab=[[],[]]
turn=True

if s[0][0]=="F":
    x-=s[0][1]
    s.pop(0)
for i in s:
    if i[0]=="F":
        ab[not turn].append(i[1])
    elif i[1]%2==1:
        turn=not turn
ab[0].sort(reverse=True)
ab[1].sort(reverse=True)
for i in ab[0]:
    x=abs(x)-abs(i)
if x!=0:
    print("No")
    exit()
for i in ab[1]:
    y=abs(y)-abs(i)
if y!=0:
    print("No")
    exit()
print("Yes")

Solution (Python):
from sys import exit
s=input()
x,y=map(int,input().split())

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
s=groupby(s)
a,b=[],[]
turn=True

if s[0][0]=="F":
    x-=s[0][1]
    s.pop(0)
for i in s:
    if i[0]=="F":
        if turn:
            a.append(i[1])
        else:
            b.append(i[1])
    elif i[1]%2==1:
        turn=not turn
a.sort(reverse=True)
b.sort(reverse=True)
for i in a:
    x=abs(x)-abs(i)
if x!=0:
    print("No")
    exit()
for i in b:
    y=abs(y)-abs(i)
if y!=0:
    print("No")
    exit()
print("Yes")

Solution (Python):
from sys import exit
s=input()
x,y=map(int,input().split())

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
s=groupby(s)
a,b=[],[]
turn=True
if s[0][0]=="F":
    x-=s[0][1]
    s.pop(0)
for i in s:
    if i[0]=="F":
        if turn:
            a.append(i[1])
        else:
            b.append(i[1])
    else:
        if i[1]%2==1:
            turn=not turn
a.sort(reverse=True)
b.sort(reverse=True)
for i in a:
    if x>0:
        x-=i
    else:
        x+=i
for i in b:
    if y>0:
        y-=i
    else:
        y+=i
if x!=0 or y!=0:
    print("No")
else:
    print("Yes")

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

i = 0
while i < len(s) and s[i] =="F":
    i += 1
x -= i
s = s[i:]

m = [[],[]]
num = 0

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



sumx = sum(m[0])

dpx = [False]*(2*sumx+3) 
dpx[sumx+1] = True


for p in m[0]:
    dpx_pre = dpx[:]
    dpx = [False]*(2*sumx+3)
    for i in range(2*sumx+3):
        if i-p >= 0:
            dpx[i-p] = dpx_pre[i] or dpx[i-p]
            
        if i+p < 2*sumx+3:
            dpx[i+p] = dpx_pre[i] or dpx[i+p]
            
    

sumy = sum(m[1])
dpy = [False]*(2*sumy+3) 
dpy[sumy+1] = True


for p in m[1]:
    dpy_pre = dpy[:]
    dpy = [False]*(2*sumy+3)
    for i in range(2*sumy+3):
        if i-p >= 0:
            dpy[i-p] = dpy_pre[i] or dpy[i-p]
        if i+p < 2*sumy+3:
            dpy[i+p] = dpy_pre[i] or dpy[i+p]
    

if abs(x) > sumx+1 or abs(y) > sumy+1:
    print("No")
elif dpx[x+(sumx+1)] and dpy[y+(sumy+1)]:
    print("Yes")
else:
    print("No")