Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

S = readline().rstrip()
gx,gy = map(int,readline().split())

C = []

import itertools
for key,g in itertools.groupby(S):
  C.append([key,len(list(g))])
  
x,y = 0,0
ind = 0
if C[0][0] == "F":
  x += C[0][1]
  ind = 1

# Xの方向を向いている
dirX = True
now = set([(x,y)])
for i in range(ind,len(C)):
  if C[i][0] == "F":
    step = C[i][1]
    nex = set()
    if dirX:
      for n in now:
        if n[0] + step <= 8000:
          nex.add((n[0] + step,n[1]))
        if n[0] - step >= -8000:
          nex.add((n[0] - step,n[1]))
    else:
      for n in now:
        if n[1] + step <= 8000:
          nex.add((n[0],n[1] + step))
        if n[1] - step >= -8000:
          nex.add((n[0],n[1] - step))
    now = nex
  else:
    if C[i][1] % 2 == 1:
      dirX ^= True
    
if (gx,gy) in now:
  print("Yes")
else:
  print("No")


Fixed submission:
S = input()
X,Y = map(int,input().split())

# [文字,その文字が連続する数]
from collections import deque
sumS = deque()
import itertools
for key,g in itertools.groupby(S):
  sumS.append([key,len(list(g))])
  
startx = 0 # Fで始まる場合はX軸の正の方向にあらかじめ進めて置く
# 最初のTが出るまではX軸正の方向に進む
if sumS[0][0] == "F":
  startx = sumS[0][1]
  sumS.popleft()

xdir = True # X軸方向を向いている
dpXcur = set()
dpXcur.add(startx)
dpYcur = set()
dpYcur.add(0) # Y軸は必ず0から始まる
dpXnex = set()
dpYnex = set()
for i in range(len(sumS)):
  if sumS[i][0] == "F":
    steps = sumS[i][1] # 進む数
    if xdir: # X軸方向を向いている場合
      for x in dpXcur:
        dpXnex.add(x + steps)
        dpXnex.add(x - steps)
      dpXcur = dpXnex
      dpXnex = set()
    else:
      for y in dpYcur:
        dpYnex.add(y + steps)
        dpYnex.add(y - steps)
      dpYcur = dpYnex
      dpYnex = set()
  elif sumS[i][0] == "T":
    turns = sumS[i][1] # 方向転換する数
    if turns % 2 == 1:
      # 奇数回の場合はX/Y軸の切り替え (偶数回の場合は何も起こらない)
      xdir ^= True
      
if X in dpXcur and Y in dpYcur:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

S = readline().rstrip()
gx,gy = map(int,readline().split())

C = []

import itertools
for key,g in itertools.groupby(S):
  C.append([key,len(list(g))])
  
x,y = 0,0
ind = 0
if C[0][0] == "F":
  x += C[0][1]
  ind = 1

# Xの方向を向いている
dirX = True
now = set([(x,y)])
for i in range(ind,len(C)):
  if C[i][0] == "F":
    step = C[i][1]
    nex = set()
    if dirX:
      for n in now:
        nex.add((n[0] + step,n[1]))
        nex.add((n[0] - step,n[1]))
    else:
      for n in now:
        nex.add((n[0],n[1] + step))
        nex.add((n[0],n[1] - step))
    now = nex
  else:
    if C[i][1] % 2 == 1:
      dirX ^= True
    
if (gx,gy) in now:
  print("Yes")
else:
  print("No")


Fixed submission:
S = input()
X,Y = map(int,input().split())

# [文字,その文字が連続する数]
from collections import deque
sumS = deque()
import itertools
for key,g in itertools.groupby(S):
  sumS.append([key,len(list(g))])
  
startx = 0 # Fで始まる場合はX軸の正の方向にあらかじめ進めて置く
# 最初のTが出るまではX軸正の方向に進む
if sumS[0][0] == "F":
  startx = sumS[0][1]
  sumS.popleft()

xdir = True # X軸方向を向いている
dpXcur = set()
dpXcur.add(startx)
dpYcur = set()
dpYcur.add(0) # Y軸は必ず0から始まる
dpXnex = set()
dpYnex = set()
for i in range(len(sumS)):
  if sumS[i][0] == "F":
    steps = sumS[i][1] # 進む数
    if xdir: # X軸方向を向いている場合
      for x in dpXcur:
        dpXnex.add(x + steps)
        dpXnex.add(x - steps)
      dpXcur = dpXnex
      dpXnex = set()
    else:
      for y in dpYcur:
        dpYnex.add(y + steps)
        dpYnex.add(y - steps)
      dpYcur = dpYnex
      dpYnex = set()
  elif sumS[i][0] == "T":
    turns = sumS[i][1] # 方向転換する数
    if turns % 2 == 1:
      # 奇数回の場合はX/Y軸の切り替え (偶数回の場合は何も起こらない)
      xdir ^= True
      
if X in dpXcur and Y in dpYcur:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

S = readline().rstrip()
gx,gy = map(int,readline().split())

C = []

import itertools
for key,g in itertools.groupby(S):
  C.append([key,len(list(g))])
  
x,y = 0,0
ind = 0
if C[0][0] == "F":
  x += C[0][1]
  ind = 1

# Xの方向を向いている
dirX = True
now = set([(x,y)])
for i in range(ind,len(C)):
  if C[i][0] == "F":
    step = C[i][1]
    nex = set()
    if dirX:
      for n in now:
        nex.add((n[0] + step,n[1]))
        nex.add((n[0] - step,n[1]))
    else:
      for n in now:
        nex.add((n[0],n[1] + step))
        nex.add((n[0],n[1] - step))
    now = nex
  else:
    if C[i][1] % 2 == 1:
      dirX ^= True
    
if (gx,gy) in now:
  print("Yes")
else:
  print("No")


Fixed submission:
S = input()
X,Y = map(int,input().split())

# [文字,その文字が連続する数]
from collections import deque
sumS = deque()
import itertools
for key,g in itertools.groupby(S):
  sumS.append([key,len(list(g))])
  
startx = 0 # Fで始まる場合はX軸の正の方向にあらかじめ進めて置く
# 最初のTが出るまではX軸正の方向に進む
if sumS[0][0] == "F":
  startx = sumS[0][1]
  sumS.popleft()

xdir = True # X軸方向を向いている
dpXcur = set()
dpXcur.add(startx)
dpYcur = set()
dpYcur.add(0) # Y軸は必ず0から始まる
dpXnex = set()
dpYnex = set()
for i in range(len(sumS)):
  if sumS[i][0] == "F":
    steps = sumS[i][1] # 進む数
    if xdir: # X軸方向を向いている場合
      for x in dpXcur:
        dpXnex.add(x + steps)
        dpXnex.add(x - steps)
      dpXcur = dpXnex
      dpXnex = set()
    else:
      for y in dpYcur:
        dpYnex.add(y + steps)
        dpYnex.add(y - steps)
      dpYcur = dpYnex
      dpYnex = set()
  elif sumS[i][0] == "T":
    turns = sumS[i][1] # 方向転換する数
    if turns % 2 == 1:
      # 奇数回の場合はX/Y軸の切り替え (偶数回の場合は何も起こらない)
      xdir ^= True
      
if X in dpXcur and Y in dpYcur:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

S = readline().rstrip()
gx,gy = map(int,readline().split())

C = []

import itertools
for key,g in itertools.groupby(S):
  C.append([key,len(list(g))])
  
x,y = 0,0
ind = 0
if C[0][0] == "F":
  x += C[0][1]
  ind = 1

# Xの方向を向いている
dirX = True
now = set([(x,y)])
for i in range(ind,len(C)):
  if C[i][0] == "F":
    nex = set()
    for n in now:
      if dirX:
        nex.add((n[0] + C[i][1],n[1]))
        nex.add((n[0] - C[i][1],n[1]))
      else:
        nex.add((n[0],n[1] + C[i][1]))
        nex.add((n[0],n[1] - C[i][1]))
    now = nex
  else:
    if C[i][1] % 2 == 1:
      dirX ^= True
    
if (gx,gy) in now:
  print("Yes")
else:
  print("No")

Fixed submission:
S = input()
X,Y = map(int,input().split())

# [文字,その文字が連続する数]
from collections import deque
sumS = deque()
import itertools
for key,g in itertools.groupby(S):
  sumS.append([key,len(list(g))])
  
startx = 0 # Fで始まる場合はX軸の正の方向にあらかじめ進めて置く
# 最初のTが出るまではX軸正の方向に進む
if sumS[0][0] == "F":
  startx = sumS[0][1]
  sumS.popleft()

xdir = True # X軸方向を向いている
dpXcur = set()
dpXcur.add(startx)
dpYcur = set()
dpYcur.add(0) # Y軸は必ず0から始まる
dpXnex = set()
dpYnex = set()
for i in range(len(sumS)):
  if sumS[i][0] == "F":
    steps = sumS[i][1] # 進む数
    if xdir: # X軸方向を向いている場合
      for x in dpXcur:
        dpXnex.add(x + steps)
        dpXnex.add(x - steps)
      dpXcur = dpXnex
      dpXnex = set()
    else:
      for y in dpYcur:
        dpYnex.add(y + steps)
        dpYnex.add(y - steps)
      dpYcur = dpYnex
      dpYnex = set()
  elif sumS[i][0] == "T":
    turns = sumS[i][1] # 方向転換する数
    if turns % 2 == 1:
      # 奇数回の場合はX/Y軸の切り替え (偶数回の場合は何も起こらない)
      xdir ^= True
      
if X in dpXcur and Y in dpYcur:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
S=input()
x,y=map(int,input().split())
import itertools
Xmove=[]
Ymove=[]
Xbase=0
Ybase=0
Xtar=True
for key,g in itertools.groupby(S):
  num=len(list(g))
  if key=="T":
    if num%2==1:
      Xtar^=True
  else:
    if Xtar:
      Xmove.append(num)
      Xbase+=num
    else:
      Ymove.append(num)
      Ybase+=num
if Xbase<x or Ybase<y:
  print("No")
  exit(0)

dpX=[[False for i in range(Xbase*2+1)] for j in range(2)]
dpY=[[False for i in range(Ybase*2+1)] for j in range(2)]
Xind=0

if S[0]=="F":
  dpX[0][Xbase+Xmove[0]]=True
  Xind=1
else:
  dpX[0][Xbase]=True
dpY[0][Ybase]=True

cur=0
for i in range(Xind,len(Xmove)):
  for j in range(len(dpX[cur])):
    if dpX[cur][j]:
      dpX[1-cur][j+Xmove[i]]=True
      dpX[1-cur][j-Xmove[i]]=True
      dpX[cur][j]=False
  cur=1-cur
  
if not dpX[cur][x+Xbase]:
  print("No")
  exit(0)
  
cur=0
for i in range(len(Ymove)):
  for j in range(len(dpY[cur])):
    if dpY[cur][j]:
      dpY[1-cur][j+Ymove[i]]=True
      dpY[1-cur][j-Ymove[i]]=True
      dpY[cur][j]=False
  cur=1-cur
  
if dpY[cur][y+Ybase]:
  print("Yes")
else:
  print("No")


Fixed submission:
S = input()
X,Y = map(int,input().split())

# [文字,その文字が連続する数]
from collections import deque
sumS = deque()
import itertools
for key,g in itertools.groupby(S):
  sumS.append([key,len(list(g))])
  
startx = 0 # Fで始まる場合はX軸の正の方向にあらかじめ進めて置く
# 最初のTが出るまではX軸正の方向に進む
if sumS[0][0] == "F":
  startx = sumS[0][1]
  sumS.popleft()

xdir = True # X軸方向を向いている
dpXcur = set()
dpXcur.add(startx)
dpYcur = set()
dpYcur.add(0) # Y軸は必ず0から始まる
dpXnex = set()
dpYnex = set()
for i in range(len(sumS)):
  if sumS[i][0] == "F":
    steps = sumS[i][1] # 進む数
    if xdir: # X軸方向を向いている場合
      for x in dpXcur:
        dpXnex.add(x + steps)
        dpXnex.add(x - steps)
      dpXcur = dpXnex
      dpXnex = set()
    else:
      for y in dpYcur:
        dpYnex.add(y + steps)
        dpYnex.add(y - steps)
      dpYcur = dpYnex
      dpYnex = set()
  elif sumS[i][0] == "T":
    turns = sumS[i][1] # 方向転換する数
    if turns % 2 == 1:
      # 奇数回の場合はX/Y軸の切り替え (偶数回の場合は何も起こらない)
      xdir ^= True
      
if X in dpXcur and Y in dpYcur:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
S=input()
x,y=map(int,input().split())
import itertools
Xmove=[]
Ymove=[]
Xbase=0
Ybase=0
Xtar=True
for key,g in itertools.groupby(S):
  num=len(list(g))
  if key=="T":
    if num%2==1:
      Xtar^=True
  else:
    if Xtar:
      Xmove.append(num)
      Xbase+=num
    else:
      Ymove.append(num)
      Ybase+=num
if Xbase<x or Ybase<y:
  print("No")
  exit(0)

dpX=[[False for i in range(Xbase*2+1)] for j in range(2)]
dpY=[[False for i in range(Ybase*2+1)] for j in range(2)]
Xind=0

if S[0]=="F":
  dpX[0][Xbase+Xmove[0]]=True
  Xind=1
else:
  dpX[0][Xbase]=True
dpY[0][Ybase]=True

cur=0
for i in range(Xind,len(Xmove)):
  for j in range(len(dpX[cur])):
    if dpX[cur][j]:
      dpX[1-cur][j+Xmove[i]]=True
      dpX[1-cur][j-Xmove[i]]=True
      dpX[cur][j]=False
  cur=1-cur
  
if not dpX[cur][x+Xbase]:
  print("No")
  exit(0)
  
cur=0
for i in range(len(Ymove)):
  for j in range(len(dpY[cur])):
    if dpY[cur][j]:
      dpY[1-cur][j+Ymove[i]]=True
      dpY[1-cur][j-Ymove[i]]=True
      dpY[cur][j]=False
  cur=1-cur
  
if dpY[cur][y+Ybase]:
  print("Yes")
else:
  print("No")


Fixed submission:
S = input()
X,Y = map(int,input().split())

# [文字,その文字が連続する数]
from collections import deque
sumS = deque()
import itertools
for key,g in itertools.groupby(S):
  sumS.append([key,len(list(g))])
  
startx = 0 # Fで始まる場合はX軸の正の方向にあらかじめ進めて置く
# 最初のTが出るまではX軸正の方向に進む
if sumS[0][0] == "F":
  startx = sumS[0][1]
  sumS.popleft()

xdir = True # X軸方向を向いている
dpXcur = set()
dpXcur.add(startx)
dpYcur = set()
dpYcur.add(0) # Y軸は必ず0から始まる
dpXnex = set()
dpYnex = set()
for i in range(len(sumS)):
  if sumS[i][0] == "F":
    steps = sumS[i][1] # 進む数
    if xdir: # X軸方向を向いている場合
      for x in dpXcur:
        dpXnex.add(x + steps)
        dpXnex.add(x - steps)
      dpXcur = dpXnex
      dpXnex = set()
    else:
      for y in dpYcur:
        dpYnex.add(y + steps)
        dpYnex.add(y - steps)
      dpYcur = dpYnex
      dpYnex = set()
  elif sumS[i][0] == "T":
    turns = sumS[i][1] # 方向転換する数
    if turns % 2 == 1:
      # 奇数回の場合はX/Y軸の切り替え (偶数回の場合は何も起こらない)
      xdir ^= True
      
if X in dpXcur and Y in dpYcur:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
S=input()
x,y=map(int,input().split())
import itertools
Xmove=[]
Ymove=[]
Xbase=0
Ybase=0
Xtar=True
for key,g in itertools.groupby(S):
  num=len(list(g))
  if key=="T":
    if num%2==1:
      Xtar^=True
  else:
    if Xtar:
      Xmove.append(num)
      Xbase+=num
    else:
      Ymove.append(num)
      Ybase+=num
if Xbase<x or Ybase<y:
  print("No")
  exit(0)

dpX=[[False for i in range(Xbase*2+1)] for j in range(2)]
dpY=[[False for i in range(Ybase*2+1)] for j in range(2)]
Xind=0

if S[0]=="F":
  dpX[0][Xbase+Xmove[0]]=True
  Xind=1
else:
  dpx[0][Xbase]=True
dpY[0][Ybase]=True

cur=0
for i in range(Xind,len(Xmove)):
  for j in range(len(dpX[cur])):
    if dpX[cur][j]:
      dpX[1-cur][j+Xmove[i]]=True
      dpX[1-cur][j-Xmove[i]]=True
      dpX[cur][j]=False
  cur=1-cur
  
if not dpX[cur][x+Xbase]:
  print("No")
  exit(0)
  
cur=0
for i in range(len(Ymove)):
  for j in range(len(dpY[cur])):
    if dpY[cur][j]:
      dpY[1-cur][j+Ymove[i]]=True
      dpY[1-cur][j-Ymove[i]]=True
      dpY[cur][j]=False
  cur=1-cur
  
if dpY[cur][y+Ybase]:
  print("Yes")
else:
  print("No")


Fixed submission:
S = input()
X,Y = map(int,input().split())

# [文字,その文字が連続する数]
from collections import deque
sumS = deque()
import itertools
for key,g in itertools.groupby(S):
  sumS.append([key,len(list(g))])
  
startx = 0 # Fで始まる場合はX軸の正の方向にあらかじめ進めて置く
# 最初のTが出るまではX軸正の方向に進む
if sumS[0][0] == "F":
  startx = sumS[0][1]
  sumS.popleft()

xdir = True # X軸方向を向いている
dpXcur = set()
dpXcur.add(startx)
dpYcur = set()
dpYcur.add(0) # Y軸は必ず0から始まる
dpXnex = set()
dpYnex = set()
for i in range(len(sumS)):
  if sumS[i][0] == "F":
    steps = sumS[i][1] # 進む数
    if xdir: # X軸方向を向いている場合
      for x in dpXcur:
        dpXnex.add(x + steps)
        dpXnex.add(x - steps)
      dpXcur = dpXnex
      dpXnex = set()
    else:
      for y in dpYcur:
        dpYnex.add(y + steps)
        dpYnex.add(y - steps)
      dpYcur = dpYnex
      dpYnex = set()
  elif sumS[i][0] == "T":
    turns = sumS[i][1] # 方向転換する数
    if turns % 2 == 1:
      # 奇数回の場合はX/Y軸の切り替え (偶数回の場合は何も起こらない)
      xdir ^= True
      
if X in dpXcur and Y in dpYcur:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
S=input()
x,y=map(int,input().split())
Xmove=[]
Ymove=[]
xdist=True
cnt=0
for i in range(len(S)):
  if S[i]=="T":
    if xdist:
      Xmove.append(cnt)
    else:
      Ymove.append(cnt)
    cnt=0
    xdist^=True
  else:
    cnt+=1
if S[-1]=="F":
  if xdist:
    Xmove.append(cnt)
  else:
    Ymove.append(cnt)

Xbase=sum(Xmove)
Ybase=sum(Ymove)
dpX=[[False for j in range(max(Xbase,x)*2+1)] for i in range(2)]
dpY=[[False for j in range(max(Ybase,y)*2+1)] for i in range(2)]

indX=0
ind=0
if S[0]=="F":
  dpX[ind][Xbase+Xmove[0]]=True
  indX=1
else:
  dpX[ind][Xbase]=True
dpY[ind][Ybase]=True

if Xbase==0:
  if x!=0:
    print("No")
    exit(0)
else:
  for i in range(indX,len(Xmove)):
    for j in range(len(dpX[ind])):
      if dpX[ind][j]:
        dpX[1-ind][j+Xmove[i]]=True
        dpX[1-ind][j-Xmove[i]]=True
    dpX[ind]=[False for _ in range(Xbase*2+1)]
    ind=1-ind

if not dpX[ind][Xbase+x]:
  print("No")
  exit(0)
  
if Ybase==0:
  if y!=0:
    print("No")
    exit(0)
else:
  ind=0
  for i in range(len(Ymove)):
    for j in range(len(dpY[ind])):
      if dpY[ind][j]:
        dpY[1-ind][j+Ymove[i]]=True
        dpY[1-ind][j-Ymove[i]]=True
    dpY[ind]=[False for _ in range(Ybase*2+1)]
    ind=1-ind
    
print(("No","Yes")[dpY[ind][Ybase+y]])

Fixed submission:
S = input()
X,Y = map(int,input().split())

# [文字,その文字が連続する数]
from collections import deque
sumS = deque()
import itertools
for key,g in itertools.groupby(S):
  sumS.append([key,len(list(g))])
  
startx = 0 # Fで始まる場合はX軸の正の方向にあらかじめ進めて置く
# 最初のTが出るまではX軸正の方向に進む
if sumS[0][0] == "F":
  startx = sumS[0][1]
  sumS.popleft()

xdir = True # X軸方向を向いている
dpXcur = set()
dpXcur.add(startx)
dpYcur = set()
dpYcur.add(0) # Y軸は必ず0から始まる
dpXnex = set()
dpYnex = set()
for i in range(len(sumS)):
  if sumS[i][0] == "F":
    steps = sumS[i][1] # 進む数
    if xdir: # X軸方向を向いている場合
      for x in dpXcur:
        dpXnex.add(x + steps)
        dpXnex.add(x - steps)
      dpXcur = dpXnex
      dpXnex = set()
    else:
      for y in dpYcur:
        dpYnex.add(y + steps)
        dpYnex.add(y - steps)
      dpYcur = dpYnex
      dpYnex = set()
  elif sumS[i][0] == "T":
    turns = sumS[i][1] # 方向転換する数
    if turns % 2 == 1:
      # 奇数回の場合はX/Y軸の切り替え (偶数回の場合は何も起こらない)
      xdir ^= True
      
if X in dpXcur and Y in dpYcur:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
x,y=map(int,input().split())
Xmove=[]
Ymove=[]
xdist=True
cnt=0
for i in range(len(S)):
  if S[i]=="T":
    if xdist:
      Xmove.append(cnt)
    else:
      Ymove.append(cnt)
    cnt=0
    xdist^=True
  else:
    cnt+=1
if S[-1]=="F":
  if xdist:
    Xmove.append(cnt)
  else:
    Ymove.append(cnt)

Xmax=sum(Xmove)
Ymax=sum(Ymove)
dpX=[[False for j in range(Xmax*2+10)] for i in range(len(Xmove)+1)]
dpY=[[False for j in range(Ymax*2+10)] for i in range(len(Ymove)+1)]

indX=0
if S[0]=="F":
  dpX[1][Xmax+Xmove[0]]=True
  indX=1
else:
  dpX[0][Xmax]=True
dpY[0][Ymax]=True

for i in range(indX,len(Xmove)):
  for j in range(len(dpX[i])):
    if dpX[i][j]:
      dpX[i+1][j-Xmove[i]]=True
      dpX[i+1][j+Xmove[i]]=True

if not dpX[-1][x+Xmax]:
  print("No")
  exit(0)

for i in range(len(Ymove)):
  for j in range(len(dpY[i])):
    if dpY[i][j]:
      dpY[i+1][j+Ymove[i]]=True
      dpY[i+1][j-Ymove[i]]=True

print(("No","Yes")[dpY[-1][y+Ymax]])

Fixed submission:
S = input()
X,Y = map(int,input().split())

# [文字,その文字が連続する数]
from collections import deque
sumS = deque()
import itertools
for key,g in itertools.groupby(S):
  sumS.append([key,len(list(g))])
  
startx = 0 # Fで始まる場合はX軸の正の方向にあらかじめ進めて置く
# 最初のTが出るまではX軸正の方向に進む
if sumS[0][0] == "F":
  startx = sumS[0][1]
  sumS.popleft()

xdir = True # X軸方向を向いている
dpXcur = set()
dpXcur.add(startx)
dpYcur = set()
dpYcur.add(0) # Y軸は必ず0から始まる
dpXnex = set()
dpYnex = set()
for i in range(len(sumS)):
  if sumS[i][0] == "F":
    steps = sumS[i][1] # 進む数
    if xdir: # X軸方向を向いている場合
      for x in dpXcur:
        dpXnex.add(x + steps)
        dpXnex.add(x - steps)
      dpXcur = dpXnex
      dpXnex = set()
    else:
      for y in dpYcur:
        dpYnex.add(y + steps)
        dpYnex.add(y - steps)
      dpYcur = dpYnex
      dpYnex = set()
  elif sumS[i][0] == "T":
    turns = sumS[i][1] # 方向転換する数
    if turns % 2 == 1:
      # 奇数回の場合はX/Y軸の切り替え (偶数回の場合は何も起こらない)
      xdir ^= True
      
if X in dpXcur and Y in dpYcur:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
S=input()
x,y=map(int,input().split())
Xmove=[]
Ymove=[]
xdist=True
cnt=0
for i in range(len(S)):
  if S[i]=="T":
    if xdist:
      Xmove.append(cnt)
    else:
      Ymove.append(cnt)
    cnt=0
    xdist^=True
  else:
    cnt+=1
if S[-1]=="F":
  if xdist:
    Xmove.append(cnt)
  else:
    Ymove.append(cnt)

Xmax=sum(Xmove)
Ymax=sum(Ymove)
dpX=[[False for j in range(Xmax*2+2)] for i in range(len(Xmove)+1)]
dpY=[[False for j in range(Ymax*2+2)] for i in range(len(Ymove)+1)]

indX=0
if S[0]=="F":
  dpX[1][Xmax+Xmove[0]]=True
  indX=1
else:
  dpX[0][Xmax]=True
dpY[0][Ymax]=True

for i in range(indX,len(Xmove)):
  for j in range(len(dpX[i])):
    if dpX[i][j]:
      dpX[i+1][j-Xmove[i]]=True
      dpX[i+1][j+Xmove[i]]=True

if not dpX[-1][x+Xmax]:
  print("No")
  exit(0)

for i in range(len(Ymove)):
  for j in range(len(dpY[i])):
    if dpY[i][j]:
      dpY[i+1][j+Ymove[i]]=True
      dpY[i+1][j-Ymove[i]]=True

print(("No","Yes")[dpY[-1][y+Ymax]])

Fixed submission:
S = input()
X,Y = map(int,input().split())

# [文字,その文字が連続する数]
from collections import deque
sumS = deque()
import itertools
for key,g in itertools.groupby(S):
  sumS.append([key,len(list(g))])
  
startx = 0 # Fで始まる場合はX軸の正の方向にあらかじめ進めて置く
# 最初のTが出るまではX軸正の方向に進む
if sumS[0][0] == "F":
  startx = sumS[0][1]
  sumS.popleft()

xdir = True # X軸方向を向いている
dpXcur = set()
dpXcur.add(startx)
dpYcur = set()
dpYcur.add(0) # Y軸は必ず0から始まる
dpXnex = set()
dpYnex = set()
for i in range(len(sumS)):
  if sumS[i][0] == "F":
    steps = sumS[i][1] # 進む数
    if xdir: # X軸方向を向いている場合
      for x in dpXcur:
        dpXnex.add(x + steps)
        dpXnex.add(x - steps)
      dpXcur = dpXnex
      dpXnex = set()
    else:
      for y in dpYcur:
        dpYnex.add(y + steps)
        dpYnex.add(y - steps)
      dpYcur = dpYnex
      dpYnex = set()
  elif sumS[i][0] == "T":
    turns = sumS[i][1] # 方向転換する数
    if turns % 2 == 1:
      # 奇数回の場合はX/Y軸の切り替え (偶数回の場合は何も起こらない)
      xdir ^= True
      
if X in dpXcur and Y in dpYcur:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
x,y=map(int,input().split())
Xmove=[]
Ymove=[]
xdist=True
cnt=0
for i in range(len(S)):
  if S[i]=="T":
    if xdist:
      Xmove.append(cnt)
    else:
      Ymove.append(cnt)
    cnt=0
    xdist^=True
  else:
    cnt+=1
if S[-1]=="F":
  if xdist:
    Xmove.append(cnt)
  else:
    Ymove.append(cnt)

dpX=[[False for j in range(16001)] for i in range(len(Xmove)+1)]
dpY=[[False for j in range(16001)] for i in range(len(Ymove)+1)]

indX=0
if S[0]=="F":
  dpX[1][8000+Xmove[0]]=True
  indX=1
else:
  dpX[0][8000]=True
dpY[0][8000]=True

for i in range(indX,len(Xmove)):
  for j in range(len(dpX[i])):
    if dpX[i][j]:
      dpX[i+1][j-Xmove[i]]=True
      dpX[i+1][j+Xmove[i]]=True


if not dpX[-1][x+8000]:
  print("No")
  exit(0)

for i in range(len(Ymove)):
  for j in range(len(dpY[i])):
    if dpY[i][j]:
      dpY[i+1][j+Ymove[i]]=True
      dpY[i+1][j-Ymove[i]]=True

print(("No","Yes")[dpY[-1][y+8000]])    
  

Fixed submission:
S = input()
X,Y = map(int,input().split())

# [文字,その文字が連続する数]
from collections import deque
sumS = deque()
import itertools
for key,g in itertools.groupby(S):
  sumS.append([key,len(list(g))])
  
startx = 0 # Fで始まる場合はX軸の正の方向にあらかじめ進めて置く
# 最初のTが出るまではX軸正の方向に進む
if sumS[0][0] == "F":
  startx = sumS[0][1]
  sumS.popleft()

xdir = True # X軸方向を向いている
dpXcur = set()
dpXcur.add(startx)
dpYcur = set()
dpYcur.add(0) # Y軸は必ず0から始まる
dpXnex = set()
dpYnex = set()
for i in range(len(sumS)):
  if sumS[i][0] == "F":
    steps = sumS[i][1] # 進む数
    if xdir: # X軸方向を向いている場合
      for x in dpXcur:
        dpXnex.add(x + steps)
        dpXnex.add(x - steps)
      dpXcur = dpXnex
      dpXnex = set()
    else:
      for y in dpYcur:
        dpYnex.add(y + steps)
        dpYnex.add(y - steps)
      dpYcur = dpYnex
      dpYnex = set()
  elif sumS[i][0] == "T":
    turns = sumS[i][1] # 方向転換する数
    if turns % 2 == 1:
      # 奇数回の場合はX/Y軸の切り替え (偶数回の場合は何も起こらない)
      xdir ^= True
      
if X in dpXcur and Y in dpYcur:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
x,y=map(int,input().split())
Xmove=[]
Ymove=[]
xdist=True
cnt=0
for i in range(len(S)):
  if S[i]=="T":
    if xdist:
      Xmove.append(cnt)
    else:
      Ymove.append(cnt)
    cnt=0
    xdist^=True
  else:
    cnt+=1
if S[-1]=="F":
  if xdist:
    Xmove.append(cnt)
  else:
    Ymove.append(cnt)

dpX=[[False for j in range(16001)] for i in range(len(Xmove)+1)]
dpY=[[False for j in range(16001)] for i in range(len(Ymove)+1)]

indX=0
if S[0]=="F":
  dpX[1][8000+Xmove[0]]=True
  indX=1
else:
  dpX[0][8000]=True
dpY[0][8000]=True

for i in range(indX,len(Xmove)):
  for j in range(len(dpX[i])):
    if dpX[i][j]:
      dpX[i+1][j-Xmove[i]]=True
      dpX[i+1][j+Xmove[i]]=True


if not dpX[-1][x+8000]:
  print("No")
  exit(0)

for i in range(len(Ymove)):
  for j in range(len(dpY[i])):
    if dpY[i][j]:
      dpY[i+1][j+Ymove[i]]=True
      dpY[i+1][j-Ymove[i]]=True

print(("No","Yes")[dpY[-1][y+8000]])    
  

Fixed submission:
S = input()
X,Y = map(int,input().split())

# [文字,その文字が連続する数]
from collections import deque
sumS = deque()
import itertools
for key,g in itertools.groupby(S):
  sumS.append([key,len(list(g))])
  
startx = 0 # Fで始まる場合はX軸の正の方向にあらかじめ進めて置く
# 最初のTが出るまではX軸正の方向に進む
if sumS[0][0] == "F":
  startx = sumS[0][1]
  sumS.popleft()

xdir = True # X軸方向を向いている
dpXcur = set()
dpXcur.add(startx)
dpYcur = set()
dpYcur.add(0) # Y軸は必ず0から始まる
dpXnex = set()
dpYnex = set()
for i in range(len(sumS)):
  if sumS[i][0] == "F":
    steps = sumS[i][1] # 進む数
    if xdir: # X軸方向を向いている場合
      for x in dpXcur:
        dpXnex.add(x + steps)
        dpXnex.add(x - steps)
      dpXcur = dpXnex
      dpXnex = set()
    else:
      for y in dpYcur:
        dpYnex.add(y + steps)
        dpYnex.add(y - steps)
      dpYcur = dpYnex
      dpYnex = set()
  elif sumS[i][0] == "T":
    turns = sumS[i][1] # 方向転換する数
    if turns % 2 == 1:
      # 奇数回の場合はX/Y軸の切り替え (偶数回の場合は何も起こらない)
      xdir ^= True
      
if X in dpXcur and Y in dpYcur:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
x,y=map(int,input().split())
xmove=[]
ymove=[]
x_dir=True
import itertools
first=True
for key,g in itertools.groupby(S):
  g=list(g)
  if key=="F":
    if first:
      x-=len(g)
    elif x_dir:
      xmove.append(len(g))
    else:
      ymove.append(len(g))
  elif key=="T":
    if len(g)%2==1:
      x_dir^=True
  first=False
  
stackX=[]
# index, move
XisOK=False
stackX.append([0,0])
while stackX:
  node=stackX.pop()
  ind=node[0]
  move=node[1]
  if ind==len(xmove):
    if x==move:
      XisOK=True
      break
    else:
      continue
  stackX.append([ind+1,move+xmove[ind]])
  stackX.append([ind+1,move+xmove[ind]*(-1)])
  
if not XisOK:
  print("No")
  exit(0)

stackY=[]
# index, move
YisOK=False
stackY.append([0,0])
while stackY:
  node=stackY.pop()
  ind=node[0]
  move=node[1]
  if ind==len(ymove):
    if y==move:
      YisOK=True
      break
    else:
      continue
  stackY.append([ind+1,move+ymove[ind]])
  stackY.append([ind+1,move+ymove[ind]*(-1)])

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

Fixed submission:
S = input()
X,Y = map(int,input().split())

# [文字,その文字が連続する数]
from collections import deque
sumS = deque()
import itertools
for key,g in itertools.groupby(S):
  sumS.append([key,len(list(g))])
  
startx = 0 # Fで始まる場合はX軸の正の方向にあらかじめ進めて置く
# 最初のTが出るまではX軸正の方向に進む
if sumS[0][0] == "F":
  startx = sumS[0][1]
  sumS.popleft()

xdir = True # X軸方向を向いている
dpXcur = set()
dpXcur.add(startx)
dpYcur = set()
dpYcur.add(0) # Y軸は必ず0から始まる
dpXnex = set()
dpYnex = set()
for i in range(len(sumS)):
  if sumS[i][0] == "F":
    steps = sumS[i][1] # 進む数
    if xdir: # X軸方向を向いている場合
      for x in dpXcur:
        dpXnex.add(x + steps)
        dpXnex.add(x - steps)
      dpXcur = dpXnex
      dpXnex = set()
    else:
      for y in dpYcur:
        dpYnex.add(y + steps)
        dpYnex.add(y - steps)
      dpYcur = dpYnex
      dpYnex = set()
  elif sumS[i][0] == "T":
    turns = sumS[i][1] # 方向転換する数
    if turns % 2 == 1:
      # 奇数回の場合はX/Y軸の切り替え (偶数回の場合は何も起こらない)
      xdir ^= True
      
if X in dpXcur and Y in dpYcur:
  print("Yes")
else:
  print("No")