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



Sample input:
FTFFTFFF
4 2


Sample output:
Yes

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
lr_check = True
ud_count = []
lr_count = []
F_count = 0

def dlr(i, p):
    global lr_count
    if i < 0:
        return 0
    if i == 0:
        if p == lr_count[0]:
            return 1
        else:
            return 0
    else:
        return dlr(i-1,p+lr_count[i-1]) + dlr(i-1,p-lr_count[i-1])
    
def dud(i, p):
    global ud_count
    if i < 0:
        return 0
    if i == 0:
        if p == ud_count[0]:
            return 1
        else:
            return 0
    else:
        return dud(i-1,p+ud_count[i-1]) + dud(i-1,p-ud_count[i-1])

for i in range(len(s)):
    if s[i] == 'T':
        if lr_check == True:
            lr_count.append(F_count)
        else:
            ud_count.append(F_count)
        lr_check = -lr_check
        F_count = 0
    else:
        F_count += 1
        if i == len(s)-1:
            if lr_check == True:
                lr_count.append(F_count)
            else:
                ud_count.append(F_count)

if lr_count == []:
    if F_count == x and 0 == y:
        print ('Yes')
    else:
        print('No')
elif ud_count == []:
    if lr_count[0] == x and 0 == y:
        print ('Yes')
    else:
        print ('No')
    
elif dud(len(ud_count)-1,abs(y))*dlr(len(lr_count)-1,abs(x)) > 0:
    print ('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import collections as col
s = input()
x,y = map(int,input().split())
col.Counter(s)
lr_check = True
ud_count = []
lr_count = []
F_count = 0

def dlr(i, p):
    global lr_count
    if i < 0:
        return 0
    if i == 0:
        if p == lr_count[0]:
            return 1
        else:
            return 0
    else:
        return dlr(i-1,p+lr_count[i-1]) + dlr(i-1,p-lr_count[i-1])
    
def dud(i, p):
    global ud_count
    if i < 0:
        return 0
    if i == 0:
        if p == ud_count[0]:
            return 1
        else:
            return 0
    else:
        return dud(i-1,p+ud_count[i-1]) + dud(i-1,p-ud_count[i-1])

for i in range(len(s)):
    if s[i] == 'T':
        if lr_check == True:
            lr_count.append(F_count)
        else:
            ud_count.append(F_count)
        lr_check = -lr_check
        F_count = 0
    else:
        F_count += 1
        if i == len(s)-1:
            if lr_check == True:
                lr_count.append(F_count)
            else:
                ud_count.append(F_count)
     
if lr_count == []:
    if F_count == x and 0 == y:
        print ('Yes')
    else:
        print('No')
elif ud_count == []:
    if lr_count[0] == x and 0 == y:
        print ('Yes')
    else:
        print ('No')
    
elif dud(len(ud_count)-1,abs(y))*dlr(len(lr_count)-1,abs(x)) > 0:
    print ('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import collections as col
s = input()
x,y = map(int,input().split())
col.Counter(s)
lr_check = True
ud_count = []
lr_count = []
F_count = 0

def dlr(i, p):
    global lr_count
    if i == 0:
        if p == lr_count[0]:
            return 1
        else:
            return 0
    else:
        return dlr(i-1,p+lr_count[i-1]) + dlr(i-1,p-lr_count[i-1])
    
def dud(i, p):
    global ud_count
    if i == 0:
        if p == ud_count[0]:
            return 1
        else:
            return 0
    else:
        return dud(i-1,p+ud_count[i-1]) + dud(i-1,p-ud_count[i-1])

for i in range(len(s)):
    if s[i] == 'T':
        if lr_check == True:
            lr_count.append(F_count)
        else:
            ud_count.append(F_count)
        lr_check = -lr_check
        F_count = 0
    else:
        F_count += 1
        if i == len(s)-1:
            if lr_check == True:
                lr_count.append(F_count)
            else:
                ud_count.append(F_count)

                
if dud(len(ud_count)-1,abs(y))*dlr(len(lr_count)-1,abs(x)) > 0:
    print ('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

def DP(i, move):
    if i < 0:
        if move == 0:
            return True
        else:
            return False
    elif i == 0:
        if move == F_list[0]:
            return True
        else:
            return False
    elif i == 1:
        if abs(move) == F_list[1]:
            return True
        else:
            return False
    else:
        return DP(i-2, move-F_list[i]) or DP(i-2, move+F_list[i])

len_F_list = len(F_list)
for i in range(len_F_list):
    F_list[i] = len(F_list[i])

if len_F_list % 2 == 1:
    i, j = len_F_list-1, -1
else:
    i, j = len_F_list-2, 1

if DP(i, x) and DP(i+j, y):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

def DP(i, move):
    if i == 0:
        if move == F_list[0]:
            return True
        else:
            return False
    elif i == 1:
        if abs(move) == F_list[1]:
            return True
        else:
            return False
    else:
        return DP(i-2, move-F_list[i]) or DP(i-2, move+F_list[i])

len_F_list = len(F_list)
for i in range(len_F_list):
    F_list[i] = len(F_list[i])

if len_F_list % 2 == 1:
    i, j = len_F_list-1, -1
else:
    i, j = len_F_list-2, 1

if DP(i, x) and DP(i+j, y):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

s = input()
x, y = list(map(int, input().split()))
s_list = s.split('T')
x_mv = []
y_mv = []

def DP(i, move, mv_list):
    if i == 0:
        if move == mv_list[0]:
            return True
        else:
            return False
    return DP(i-1, move-mv_list[i], mv_list) or DP(i-1, move+mv_list[i], mv_list)

for i in range(len(s_list)):
    if i % 2 == 0:
        x_mv.append(len(s_list[i]))
    else:
        y_mv.append(len(s_list[i]))

i = len(x_mv) - 1
if DP(i, x, x_mv):
    i = len(y_mv) - 1
    if DP(i, y, y_mv) or DP(i, -y, y_mv):
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys

UP    = 0
RIGHT = 1
DOWN  = 2
LEFT  = 3

dx = [0, 1, 0, -1]
dy = [-1, 0, 1, 0]

x_dst = None
y_dst = None

def dfs(x, y, d, S):


    if len(S) == 0:
        if x == x_dst and y == y_dst:
            print("Yes")
            sys.exit()
        else:
            return

    if S[0] == "F":
        dfs(x+dx[d], y+dy[d], d, S[1:])
    else:
        dfs(x, y, (d-1)%4, S[1:])
        dfs(x, y, (d+1)%4, S[1:])

def main():
    global x_dst
    global y_dst

    S = input()
    x_dst, y_dst = list(map(int, input().split()))

    x, y = 0, 0
    d = RIGHT

    dfs(x, y, d, S)

    print("No")

main()

Submission status: Runtime Error

Solution code:
import sys

def check_ans(s,x):
  if len(s)==0 and x!=0:
    return False
  elif len(s)==0 and x==0:
    return True
  a=len(s)+1
  dp=[[False for i in range(8001)] for j in range(len(s)+1)]
  dp[1][s[0]]=True
  for i in range(1,len(s)):
    for j in range(0,8002):
      if dp[i][j]:
        res=abs(j+s[i])
        res2=abs(j-s[i])
        dp[i+1][res]=True
        dp[i+1][res2]=True
  return dp[len(s)][x]

S = sys.stdin.readline().strip()
X,Y=map(int,input().split())
d=1
while S and S[0]=='F':
  S=S[1:]
  X-=1
if len(S)==0:
  if X==0:
    print("Yes")
  else:
    print("No")
  sys.exit()

nx=[]
ny=[]
X=abs(X)
Y=abs(Y)

while S:
  step=0
  while S and S[0]=='T':
    d*=-1
    S=S[1:]
  while S and S[0]=='F':
    step+=1
    S=S[1:]
  if step==0:
    break
  if d==1:
    nx.append(step)
  else:
    ny.append(step)

if check_ans(nx,X) and check_ans(ny,Y):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
import sys

def check_ans(s,x):
  if len(s)==0 and x!=0:
    return False
  elif len(s)==0 and x==0:
    return True
  dp=[[False] * 8001] *(len(s)+1)
  dp[1][s[0]]=True
  for i in range(1,len(s)):
    for j in range(0,8002):
      if dp[i][j]:
        res=abs(j+s[i])
        res2=abs(j-s[i])
        dp[i+1][res]=True
        dp[i+1][res2]=True
  return dp[len(s)][x]

S = sys.stdin.readline().strip()
X,Y=map(int,input().split())
d=1
while S and S[0]=='F':
  S=S[1:]
  X-=1
if len(S)==0:
  if X==0:
    print("Yes")
  else:
    print("No")
  sys.exit()

nx=[]
ny=[]
X=abs(X)
Y=abs(Y)

while S:
  step=0
  while S and S[0]=='T':
    d*=-1
    S=S[1:]
  while S and S[0]=='F':
    step+=1
    S=S[1:]
  if d==1:
    nx.append(step)
  else:
    ny.append(step)

if check_ans(nx,X) and check_ans(ny,Y):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
import sys

def check_ans(s,x):
  if len(s)==0 and x!=0:
    return False
  elif len(s)==0 and x==0:
    return True
  dp=[[False] * 8001] *(len(s)+1)
  dp[1][s[0]]=True
  for i in range(1,len(s)):
    for j in range(0,8002):
      if dp[i][j]:
        res=abs(j+s[i])
        res2=abs(j-s[i])
        dp[i+1][res]=True
        dp[i+1][res2]=True
  return dp[len(s)][x]

S = sys.stdin.readline().strip()
X,Y=map(int,input().split())
d=1
while S[0]=='F':
  S=S[1:]
  X-=1
nx=[]
ny=[]
X=abs(X)
Y=abs(Y)

while S:
  step=0
  while S and S[0]=='T':
    d*=-1
    S=S[1:]
  while S and S[0]=='F':
    step+=1
    S=S[1:]
  if d==1:
    nx.append(step)
  else:
    ny.append(step)

if check_ans(nx,X) and check_ans(ny,Y):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
import sys

def check_ans(s,x):
  for i in range(0,2**len(s)):
    ans=0
    for j in range(len(s)):
      if (i>>j)%2:
        ans+=s[j]
      else:
        ans-=s[j]
    if ans==x:
      return True
  return False

S = sys.stdin.readline().strip()
X,Y=map(int,input().split())
d=1
while S[0]=='F':
  S=S[1:]
  X-=1
nx=[]
ny=[]

while S:
  step=0
  while S and S[0]=='T':
    d*=-1
    S=S[1:]
  while S and S[0]=='F':
    step+=1
    S=S[1:]
  if d==1:
    nx.append(step)
  else:
    ny.append(step)

if check_ans(nx,X) and check_ans(ny,Y):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
def check_ans(s,x):
  for i in range(0,2**len(s)):
    ans=0
    for j in range(len(s)):
      if (i>>j)%2:
        ans+=s[j]
      else:
        ans-=s[j]
    if ans==x:
      return True
  return False

S=input()
X,Y=map(int,input().split())
d=1
while S[0]=='F':
  S=S[1:]
  X-=1
nx=[]
ny=[]

while S:
  step=0
  while S and S[0]=='T':
    d*=-1
    S=S[1:]
  while S and S[0]=='F':
    step+=1
    S=S[1:]
  if d==1:
    nx.append(step)
  else:
    ny.append(step)
  if len(S)==1:
    break

if check_ans(nx,X) and check_ans(ny,Y):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
def check_ans(s,x):
  res=sum(s)
  if res<x:
    return False
  for i in range(0,2**len(s)):
    ans=res
    for j in range(len(s)):
      if (i>>j)%2:
        ans-=s[j]
    if ans==x:
      return True
  return False

S=input()
X,Y=map(int,input().split())
d=1
while S[0]=='F':
  S=S[1:]
  X-=1
nx=[]
ny=[]
X=abs(X)
Y=abs(Y)

while S:
  step=0
  while S and S[0]=='T':
    d*=-1
    S=S[1:]
  while S and S[0]=='F':
    step+=1
    S=S[1:]
  if d==1:
    nx.append(step)
  else:
    ny.append(step)
  if len(S)==1:
    break

if check_ans(nx,X) and check_ans(ny,Y):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys
import numpy as np
sys.setrecursionlimit(8002)

def reachable(cp, cv, tp, rl, s, i, l):
    # print i, cp, cv
    if (i > l):
        if np.array_equal(cp, tp):
            return True
        else:
            return False
    cmd = s[i]
    if cmd == 'F':
        return reachable(cp + cv, cv, tp, rl, s, i+1, l)
    else:
        nv = rl[tuple(cv)]
        if reachable(cp, nv[0], tp, rl, s, i+1, l):
            return True
        else:
            return reachable(cp, nv[1], tp, rl, s, i+1, l)

s = raw_input().split()[0]
x, y = [int(e) for e in raw_input().split()]
# print s
# print x, y

cp = np.array([0,0])
cv = np.array([1,0])
tp = np.array([x,y])

rl = {
    ( 1, 0):[np.array([ 0, 1]), np.array([ 0,-1])],
    ( 0, 1):[np.array([-1, 0]), np.array([ 1, 0])],
    (-1, 0):[np.array([ 0,-1]), np.array([ 0, 1])],
    ( 0,-1):[np.array([ 1, 0]), np.array([-1, 0])],
}

if reachable(cp, cv, tp, rl, s, 0, len(s) - 1):
    sys.stdout.write('Yes\n')
else:
    sys.stdout.write('No\n')
sys.stdout.flush()

Submission status: Runtime Error

Solution code:
s = input()
x, y = map(int, input().split())
hL = len(s)
L = 2 * hL

dp = [[False] * L for i in range(2)]

def next(i):
    global s
    while i < hL and s[i] != 'T':
        i += 1
    i += 1
    # print('i: %d' % i)
    return i

def c(x):
    global hL
    return x + hL

index = 0
t = 0
dp[0][c(0)] = True
dp[1][c(0)] = True
# print('\n'.join(map(str, dp)))
while index < hL:
    nt = (t + 1) % 2
    ndp = [False] * L
    ni = next(index)
    dx, index = ni - index - 1, ni
    for i in range(-hL, hL, 1):
        for j in [-1, 1]:
            if -hL <= i + j * dx < hL:
                nx = c(i + j * dx)
                ndp[nx] = ndp[nx] or dp[t][c(i)]
    dp[t] = ndp
    # print('\n'.join(map(str, dp)))
    t = nt
# print('\n'.join(map(str, dp)))
# print(dp[0][c(x)], dp[1][c(y)])
print('Yes' if dp[0][c(x)] and dp[1][c(y)] else 'No')

Submission status: Runtime Error

Solution code:
st = input().split("T")
x, y = map(int, input().split())
XL = []; YL = []; T = 10
for i in range(len(st)):
    if i % 2 == 0:
        XL.append(len(st[i]))
    else:
        YL.append(len(st[i]))
    T += len(st[i])

xx = [[False for j in range(2*T+1)] for i in range(len(XL)+1)]
yy = [[False for j in range(2*T+1)] for i in range(len(YL)+1)]
xx[0][T]=True
yy[0][T]=True
xx[1][T+XL[0]]=True
for i in range(2, len(XL)+1):
    for j in range(2*T+1):
        if j-XL[i-1] < 0:
            xx[i][j]=xx[i-1][j+XL[i-1]]
        elif j+XL[i-1] > 2*T:
            xx[i][j]=xx[i-1][j-XL[i-1]]
        else:
            xx[i][j]=xx[i-1][j-XL[i-1]] or xx[i-1][j+XL[i-1]]

for i in range(1,len(YL)+1):
    for j in range(2*T+1):
        if j-YL[i-1] < 0:
            yy[i][j]=yy[i-1][j+YL[i-1]]
        elif j+YL[i-1] > 2*T:
            yy[i][j]=yy[i-1][j-YL[i-1]]
        else:
            yy[i][j]=yy[i-1][j-YL[i-1]] or yy[i-1][j+YL[i-1]]

if xx[len(XL)][x+T] and yy[len(YL)][y+T]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
st = input().split("T")
x, y = map(int, input().split())
XL = []; YL = []; T = 3
for i in range(len(st)):
    if i % 2 == 0:
        XL.append(len(st[i]))
    else:
        YL.append(len(st[i]))
    T += len(st[i])

xx = [[False for j in range(2*T+1)] for i in range(len(XL)+1)]
yy = [[False for j in range(2*T+1)] for i in range(len(YL)+1)]
xx[0][T]=True
yy[0][T]=True
xx[1][T+XL[0]]=True
for i in range(2, len(XL)+1):
    for j in range(2*T+1):
        if j-XL[i-1] < 0:
            xx[i][j]=xx[i-1][j+XL[i-1]]
        elif j+XL[i-1] > 2*T:
            xx[i][j]=xx[i-1][j-XL[i-1]]
        else:
            xx[i][j]=xx[i-1][j-XL[i-1]] or xx[i-1][j+XL[i-1]]

for i in range(1,len(YL)+1):
    for j in range(2*T+1):
        if j-YL[i-1] < 0:
            yy[i][j]=yy[i-1][j+YL[i-1]]
        elif j+YL[i-1] > 2*T:
            yy[i][j]=yy[i-1][j-YL[i-1]]
        else:
            yy[i][j]=yy[i-1][j-YL[i-1]] or yy[i-1][j+YL[i-1]]

if xx[len(XL)][x+T] and yy[len(YL)][y+T]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
st = input().split("T")
x, y = map(int, input().split())
XL = []; YL = []; T = 0
for i in range(len(st)):
    if i % 2 == 0:
        XL.append(len(st[i]))
    else:
        YL.append(len(st[i]))
    T += len(st[i])
T += 2
xx = [[False for j in range(2*T+1)] for i in range(len(XL)+1)]
yy = [[False for j in range(2*T+1)] for i in range(len(YL)+1)]
xx[0][T]=True
yy[0][T]=True
xx[1][T+XL[0]]=True
for i in range(2, len(XL)+1):
    for j in range(2*T+1):
        if j-XL[i-1] < 0:
            xx[i][j]=xx[i-1][j+XL[i-1]]
        elif j+XL[i-1] > 2*T:
            xx[i][j]=xx[i-1][j-XL[i-1]]
        else:
            xx[i][j]=xx[i-1][j-XL[i-1]] or xx[i-1][j+XL[i-1]]

for i in range(1,len(YL)+1):
    for j in range(2*T+1):
        if j-YL[i-1] < 0:
            yy[i][j]=yy[i-1][j+YL[i-1]]
        elif j+YL[i-1] > 2*T:
            yy[i][j]=yy[i-1][j-YL[i-1]]
        else:
            yy[i][j]=yy[i-1][j-YL[i-1]] or yy[i-1][j+YL[i-1]]

if xx[len(XL)][x+T] and yy[len(YL)][y+T]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
st = input().split("T")
x, y = map(int, input().split())
XL = []; YL = []; T = 0
for i in range(len(st)):
    if i % 2 == 0:
        XL.append(len(st[i]))
    else:
        YL.append(len(st[i]))
    T += len(st[i])

xx = [[False for j in range(2*T+1)] for i in range(len(XL)+1)]
yy = [[False for j in range(2*T+1)] for i in range(len(YL)+1)]
xx[0][T]=True
yy[0][T]=True
xx[1][T+XL[0]]=True
for i in range(2, len(XL)+1):
    for j in range(2*T+1):
        if j-XL[i-1] < 0:
            xx[i][j]=xx[i-1][j+XL[i-1]]
        elif j+XL[i-1] > 2*T:
            xx[i][j]=xx[i-1][j-XL[i-1]]
        else:
            xx[i][j]=xx[i-1][j-XL[i-1]] or xx[i-1][j+XL[i-1]]

for i in range(1,len(YL)+1):
    for j in range(2*T+1):
        if j-YL[i-1] < 0:
            yy[i][j]=yy[i-1][j+YL[i-1]]
        elif j+YL[i-1] > 2*T:
            yy[i][j]=yy[i-1][j-YL[i-1]]
        else:
            yy[i][j]=yy[i-1][j-YL[i-1]] or yy[i-1][j+YL[i-1]]

if xx[len(XL)][x+T] and yy[len(YL)][y+T]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = input()
F_cnt = [len(f) for f in s.split('T')]

x, y = map(int, input().split())
x_all = y_all = {0}

for i in range(len(F_cnt)):
    x_posi = x_nega = y_posi = y_nega = set()
    if i == 0:
        x_posi = {n + F_cnt[i] for n in x_all}
    elif i % 2 == 0:
        for n in x_all:
            x_posi = n + F_cnt[i]
            x_nega = n - F_cnt[i]
    else:
        for n in y_all:
            y_posi = n + F_cnt[i]
            y_nega = n - F_cnt[i]
    x_all |= x_posi | x_nega
    y_all |= y_posi | y_nega

if x in x_all and y in y_all:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc082/tasks/arc087_b

"""
import sys
from sys import stdin
input = stdin.readline


def check_x(forwards):
    n = sum(forwards[::2])      #  x軸方向への最大移動量
    dpx = [False] * (n * 2 + 1) #  真ん中を0として、±両方向のdp領域を確保
    dpx[forwards[0] + n] = True #  最初は0からプラス方向に移動

    for f in forwards[2::2]:
        if f == 0:
            continue
        n_move = dpx[f:] + [False]*f
        p_move = [False]*f + dpx[:-f]
        t = [a or b for a, b in zip(n_move, p_move)]
        dpx = t
    return dpx, n


def check_y(forwards):
    n = sum(forwards[1::2])
    dpy = [False] * (n * 2 + 1)
    dpy[n] = True

    for f in forwards[1::2]:
        if f == 0:
            continue
        n_move = dpy[f:] + [False]*f
        p_move = [False]*f + dpy[:-f]
        t = [a or b for a, b in zip(n_move, p_move)]
        dpy = t
    return dpy, n


def solve(s, gx, gy):
    forwards = [len(x) for x in s.split('T')] #  進む歩数情報の数字に変換
    dpx, zx = check_x(forwards)
    dpy, zy = check_y(forwards)

    if zx < gx:
        return 'No'
    if zy < gy:
        return 'No'
    if dpx[gx + zx] is True and dpy[gy + zy] is True:
        return 'Yes'
    else:
        return 'No'


def main(args):
    s = input().strip()
    gx, gy = map(int, input().split())
    ans = solve(s, gx, gy)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc082/tasks/arc087_b

"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline


def check_x(forwards):
    n = sum(forwards[::2])
    dpx = [False] * (n * 2 + 1)
    dpx[forwards[0] + n] = True

    for f in forwards[2::2]:
        if f == 0:
            continue
        n_move = dpx[f:] + [False]*f
        p_move = [False]*f + dpx[:-f]
        t = [a or b for a, b in zip(n_move, p_move)]
        dpx = t
    return dpx, n


def check_y(forwards):
    n = sum(forwards[1::2])
    dpy = [False] * (n * 2 + 1)
    dpy[n] = True

    for f in forwards[1::2]:
        if f == 0:
            continue
        n_move = dpy[f:] + [False]*f
        p_move = [False]*f + dpy[:-f]
        t = [a or b for a, b in zip(n_move, p_move)]
        dpy = t
    return dpy, n


def solve(s, gx, gy):
    n = len(s)
    forwards = [len(x) for x in s.split('T')]

    dpx, zx = check_x(forwards)
    dpy, zy = check_y(forwards)

    if len(dpy)-1 < gy or len(dpx)-1 < gx:
        return 'No'
    elif dpy[gy + zy] is True and dpx[gx + zx] is True:
        return 'Yes'
    else:
        return 'No'


def main(args):
    s = input().strip()
    gx, gy = map(int, input().split())
    # s = 'TFFTTFTFFFFTTFTTTFFFFFTTFFTTFTFTFFFTTFFFTTTFTFTFTFFTFFTFFFTFFFFFFTFFFFFFFTF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FFTFTFTFFFTFFFTFFFFFFTFTFFFTFFTFFFFFFFTFTFTTFTTFFTTFTFTFFFFTFFFFTFFFTFTFTFFTFTFFFTFFFTFTFFFFFTFFTFTFTFTFFFFTTTFFFTTFFTFFFTTFFFTFTFFFFFTFFFFTFTFTTFFFFFTFTFFFFFFFTFFFFFFTFTTFFFTFFFFFFFFTFFTFFFFTFFTFFTFFFFTFFFFFFTFTFFFTTTFFFTTFFTTTTTFFFTFFTTFFFTTFFFFTFFFTFFTTFFTFFFFFTFTFTTTTFTTFTTTFTFFFFTTFTTFFFTFFFFTTTTTFFTFFFTFTFTFTTFTFTFTFFFFFFTTFFTFFFFFFFFTFTFFTFTTFTFFTTFTFTTTFFTTTTFFTFFFFFFFTTFFTFFFFFFTTTTFFFFFFFFTFTFFFFFTTFTFFFFTTFFFFTTFTTFFTFTTFFTFTFFTFFFTTFFTFFTFTFTTFTTFFFTTFTFTFTFFFTTFTTFTTFFFTFFFFFTFFFFFFFTFTFFFTTFFFTTFTTFTFFFFFFFFFFTFFFTTFTTTTFFTFFFFFTFTTFTFTFFFFTFTFFFFFFFTFFTTTTFTFFTFFFFFFFTTFTFFTFFFFFTFFFFFFTFFFFTFFTFFTTFTFTTFFTFFFTFTFTFFFFFFTTTFFTTTFFTFFTFTTTFTFFTFFTFFFFTFTFFTTFTTTTFTTFTFTTFFFFFFTFTFTFFFFFTTFFFFFFTTFFFFFTFFFTFTFTTTFFFTFFTFTFFFFFFTFFFTFF'
    # s = 'FTFFTFFF'
    # gx, gy = 4, 2
    ans = solve(s, gx, gy)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Runtime Error

Solution code:
import sys

def check(s, x, y):

    while s and s[0] == "F":
        s = s[1:]
        x -= 1
    while s and s[-1] == "T":
        s = s[:-1]

    d = 0
    vxs = []
    vys = []
    while s:
        while s and s[0] == "T":
            s = s[1:]
            d ^= 1
        l = 0
        while s and s[0] == "F":
            s = s[1:]
            l += 1
        if d:
            vys.append(l)
        else:
            vxs.append(l)

    def check1(vs, t):
        def check2(i, p, cache={}):
            if i == 0:
                return p == t
            if (i, p) in cache:
                return cache[i, p]
            r =  check2(i - 1, p - vs[i-1]) or check2(i - 1, p + vs[i-1])
            cache[i, p] = r
            return r
        return check2(len(vs), 0)

    r = check1(vxs, x) and check1(vys, y)
    return r

if __name__ == "__main__":
    s = sys.stdin.readline().strip()
    x, y = [int(n) for n in sys.stdin.readline().strip().split()]
    if check(s, x, y):
        print("Yes")
    else:
        print("No")