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:
string = raw_input()
x_,y_ = map(int, raw_input().split())

face = 0

for c in string:
	if c == "F":
		if face == 0:
			x += 1
		elif face == 1:
			y += 1
		elif face == 2:
			x -= 1
		elif face == 3:
			y -= 1
	elif c == "T":
		face = (face + 1)%4

if x == x_ and y == y_:
	print "YES"
else:
	print "NO"

Submission status: Runtime Error

Solution code:
inp=list(map(len,input().split("T")))
inx,iny=list(map(int,input().split()))
memo={}
def tg(g,n,t):
 g.sort()
 g.reverse()
 def tn(g,n,t):
  if (tuple(g),n,t) in memo:
   return memo[(tuple(g),n,t)]
  if g==[]:
   if n==t:
    return True
   else:
    return False
  if n<t:
   z=tn(g[1:],n+g[0],t)
   memo[(tuple(g),n,t)]=z
   return z
  else:
   z=tn(g[1:],n-g[0],t)
   memo[(tuple(g),n,t)]=z
   return z
 return tn(g,n,t)
 
if tg(inp[1::2],0,iny)and tg(inp[2::2],inp[0],inx):
 print("Yes")
else:
 print("No")

Submission status: Runtime Error

Solution code:
inp=list(map(len,input().split("T")))
inx,iny=list(map(int,input().split()))
memo={}
def tg(g,n,t):
 if (tuple(g),n,t) in memo:
  return memo[(tuple(g),n,t)]
 if g==[]:
  if n==t:
   return True
  else:
   return False
 if tg(g[1:],n+g[0],t)or tg(g[1:],n-g[0],t):
  memo[(tuple(g),n,t)]=True
  return True
 else:
  memo[(tuple(g),n,t)]=False
  return False

if tg(inp[1::2],0,iny)and tg(inp[2::2],inp[0],inx):
 print("Yes")
else:
 print("No")

Submission status: Runtime Error

Solution code:
inp=list(map(len,input().split("T")))
inx,iny=list(map(int,input().split()))
memo={}
def tg(g,n,t):
 if (g,n,t) in memo:
  return memo[(g,n,t)]
 if tg(g[1:],n+g[0],t)or tg(g[1:],n-g[0],t):
  memo[(g,n,t)]=True
  return True
 else:
  memo[(g,n,t)]=False
  return False

if tg(inp[1::2],0,iny)and tg(inp[2::2],inp[0],inx):
 print("Yes")
else:
 print("No")

Submission status: Runtime Error

Solution code:
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def S(): return input()

s = S()
gx,gy = Is()
xlis,ylis = [],[]
x,y = 0,0
h = 0
for e in s:
    if e == "F":
        if h == 0:
            x += 1 
        else:
            y += 1 
    else:
        if h == 0:
            if x:
                xlis.append(x) 
        else:
            if y:
                ylis.append(y)
        x,y = 0,0
        h = not h
if h == 0:
    if x:
        xlis.append(x) 
else:
    if y:
        ylis.append(y)
sx = xlis.pop(0) if len(xlis)>0 else 0
sy = 0
xmat = [[False]*16001 for i in range(len(xlis)+1)]
ymat = [[False]*16001 for i in range(len(ylis)+1)]
xmat[0][sx] = True
ymat[0][sy] = True
def xdp(i,d):
    if xmat[i][d]:
        return True
    if i == 0:
        return False
    xmat[i][d] = xdp(i-1,d + xlis[i-1]) or xdp(i-1,d - xlis[i-1])
    return xmat[i][d]
def ydp(i,d):
    if ymat[i][d]:
        return True
    if i == 0:
        return False
    ymat[i][d] = ydp(i-1,d + ylis[i-1]) or ydp(i-1,d - ylis[i-1])
    return xmat[i][d]
if xdp(len(xlis),gx) and ydp(len(ylis),gy):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def S(): return input()

s = S()
gx,gy = Is()
xlis,ylis = [],[]
x,y = 0,0
h = 0
for e in s:
    if e == "F":
        if h == 0:
            x += 1 
        else:
            y += 1 
    else:
        if h == 0:
            if x:
                xlis.append(x) 
        else:
            if y:
                ylis.append(y)
        x,y = 0,0
        h = not h
if h == 0:
    if x:
        xlis.append(x) 
else:
    if y:
        ylis.append(y)
sx = xlis.pop(0) if len(xlis)>0 else 0
sy = 0
xmat = [[False]*16001 for i in range(len(xlis)+1)]
ymat = [[False]*16001 for i in range(len(ylis)+1)]
xmat[0][sx] = True
ymat[0][sy] = True
def xdp(i,d):
    if xmat[i][d]:
        return True
    if i == 0:
        return False
    xmat[i][d] = xdp(i-1,d + lis[i-1]) or xdp(i-1,d - lis[i-1])
    return xmat[i][d]
def ydp(i,d):
    if ymat[i][d]:
        return True
    if i == 0:
        return False
    ymat[i][d] = ydp(i-1,d + lis[i-1]) or ydp(i-1,d - lis[i-1])
    return xmat[i][d]
if xdp(len(xlis),gx) and ydp(len(ylis),gy):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
S=str(input())
S=S[:len(S)-1]
s=list(S)
x,y=map(int,input().split())
fora=0
side=[]
updw=[]
while s[0]=="F":
  fora+=1
  s.pop(0)
  if len(s)==0:break
flag=1#1のとき横向き、-1のときたて向き
step=0
while s:
  if s[0]=="T":
    s.pop(0)
    if step:
      if flag==-1: updw+=[step]
      else: side+=[step]
    flag=flag*(-1)
    step=0
  else:
    s.pop(0)
    step+=1
    if len(s)==0:
      if flag==-1: updw+=[step]
      else: side+=[step]
ypossi=len(side)
tpossi=len(updw)
X=sum(side)+fora+x
Y=sum(updw)+y
xdp=[[0 for i in range(2*X+1)] for j in range(ypossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
xdp[0][fora+X]=1 
for i in range(ypossi):
  for j in range(2*X+1):
    if j-side[i]>=0:
      if xdp[i][j-side[i]]==1:xdp[i+1][j]=1
    if j+side[i]<2*X+1:
      if xdp[i][j+side[i]]==1:xdp[i+1][j]=1

ydp=[[0 for i in range(2*Y+1)] for j in range(tpossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
ydp[0][Y]=1 
for i in range(tpossi):
  for j in range(2*Y+1):
    if j-updw[i]>=0:
      if ydp[i][j-updw[i]]==1:ydp[i+1][j]=1
    if j+updw[i]<2*Y+1:
      if ydp[i][j+updw[i]]==1:ydp[i+1][j]=1
if xdp[ypossi][x+X]==1 and ydp[tpossi][y+Y]==1:
  print("Yes")
else: print("No")

Submission status: Runtime Error

Solution code:
S=str(input())
s=list(S)
x,y=map(int,input().split())
fora=0
side=[]
updw=[]
while s[0]=="F":
  fora+=1
  s.pop(0)
  if len(s)==0:break
flag=1#1のとき横向き、-1のときたて向き
step=0
while s:
  if s[0]=="T":
    s.pop(0)
    if step:
      if flag==-1: updw+=[step]
      else: side+=[step]
    flag=flag*(-1)
    step=0
  else:
    s.pop(0)
    step+=1
    if len(s)==0:
      if flag==-1: updw+=[step]
      else: side+=[step]
ypossi=len(side)
tpossi=len(updw)
X=sum(side)+fora+x
Y=sum(updw)+y
xdp=[[0 for i in range(2*X+1)] for j in range(ypossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
xdp[0][fora+X]=1 
for i in range(ypossi):
  for j in range(2*X+1):
    if j-side[i]>=0:
      if xdp[i][j-side[i]]==1:xdp[i+1][j]=1
    if j+side[i]<2*X+1:
      if xdp[i][j+side[i]]==1:xdp[i+1][j]=1

ydp=[[0 for i in range(2*Y+1)] for j in range(tpossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
ydp[0][Y]=1 
for i in range(tpossi):
  for j in range(2*Y+1):
    if j-updw[i]>=0:
      if ydp[i][j-updw[i]]==1:ydp[i+1][j]=1
    if j+updw[i]<2*Y+1:
      if ydp[i][j+updw[i]]==1:ydp[i+1][j]=1
if xdp[ypossi][x+X]==1 and ydp[tpossi][y+Y]==1:
  print("Yes")
else: print("No")

Submission status: Runtime Error

Solution code:
S=str(input())
s=list(S)
x,y=map(int,input().split())
fora=0
side=[]
updw=[]
while s[0]=="F":
  fora+=1
  s.pop(0)
flag=1#1のとき横向き、-1のときたて向き
step=0
while s:
  if s[0]=="T":
    s.pop(0)
    if step:
      if flag==-1: updw+=[step]
      else: side+=[step]
    flag=flag*(-1)
    step=0
  else:
    s.pop(0)
    step+=1
    if len(s)==0:
      if flag==-1: updw+=[step]
      else: side+=[step]
ypossi=len(side)
tpossi=len(updw)
X=sum(side)+fora+x
Y=sum(updw)+y
xdp=[[0 for i in range(2*X+1)] for j in range(ypossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
xdp[0][fora+X]=1 
for i in range(ypossi):
  for j in range(2*X+1):
    if j-side[i]>=0:
      if xdp[i][j-side[i]]==1:xdp[i+1][j]=1
    if j+side[i]<2*X+1:
      if xdp[i][j+side[i]]==1:xdp[i+1][j]=1

ydp=[[0 for i in range(2*Y+1)] for j in range(tpossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
ydp[0][Y]=1 
for i in range(tpossi):
  for j in range(2*Y+1):
    if j-updw[i]>=0:
      if ydp[i][j-updw[i]]==1:ydp[i+1][j]=1
    if j+updw[i]<2*Y+1:
      if ydp[i][j+updw[i]]==1:ydp[i+1][j]=1
if xdp[ypossi][x+X]==1 and ydp[tpossi][y+Y]==1:
  print("Yes")
else: print("No")

Submission status: Runtime Error

Solution code:
S=str(input())
s=list(S)
x,y=map(int,input().split())
fora=0
side=[]
updw=[]
while s[0]=="F":
  fora+=1
  s.pop(0)
flag=1#1のとき横向き、-1のときたて向き
step=0
while s:
  if s[0]=="T":
    s.pop(0)
    if step:
      if flag==-1: updw+=[step]
      else: side+=[step]
    flag=flag*(-1)
    step=0
  else:
    s.pop(0)
    step+=1
    if len(s)==0:
      if flag==-1: updw+=[step]
      else: side+=[step]
ypossi=len(side)
tpossi=len(updw)
xdp=[[0 for i in range(2*len(S)+1)] for j in range(ypossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
xdp[0][fora+len(S)]=1 
for i in range(ypossi):
  for j in range(2*len(S)+1):
    if j-side[i]>=0:
      if xdp[i][j-side[i]]==1:xdp[i+1][j]=1
    if j+side[i]<2*len(S)+1:
      if xdp[i][j+side[i]]==1:xdp[i+1][j]=1
        
ydp=[[0 for i in range(2*len(S)+1)] for j in range(tpossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
ydp[0][len(S)]=1 
for i in range(tpossi):
  for j in range(2*len(S)+1):
    if j-updw[i]>=0:
      if ydp[i][j-updw[i]]==1:ydp[i+1][j]=1
    if j+updw[i]<2*len(S)+1:
      if ydp[i][j+updw[i]]==1:ydp[i+1][j]=1
if xdp[ypossi][x+len(S)]==1 and ydp[tpossi][y+len(S)]==1:
  print("Yes")
else: print("No")

Submission status: Runtime Error

Solution code:
S=input()
S=S[:len(S)-1]
s=list(S)
x,y=map(int,input().split())
fora=0
side=[]
updw=[]
while s[0]=="F":
  fora+=1
  s.pop(0)
  if len(s)==0: break
flag=1#1のとき横向き、-1のときたて向き
step=0
while s:
  if s[0]=="T":
    s.pop(0)
    if flag==-1: updw+=[step]
    else: side+=[step]
    flag=flag*(-1)
    step=0
  else:
    s.pop(0)
    step+=1
    if len(s)==0:
      if flag==-1: updw+=[step]
      else: side+=[step]
ypossi=len(side)
tpossi=len(updw)
X=sum(side)+fora+x
Y=sum(updw)+y
xdp=[[0 for i in range(2*X+1)] for j in range(ypossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
xdp[0][fora+X]=1 
for i in range(ypossi):
  for j in range(2*X+1):
    if j-side[i]>=0:
      if xdp[i][j-side[i]]==1:xdp[i+1][j]=1
    if j+side[i]<2*X+1:
      if xdp[i][j+side[i]]==1:xdp[i+1][j]=1
        
ydp=[[0 for i in range(2*Y+1)] for j in range(tpossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
ydp[0][Y]=1 
for i in range(tpossi):
  for j in range(2*Y+1):
    if j-updw[i]>=0:
      if ydp[i][j-updw[i]]==1:ydp[i+1][j]=1
    if j+updw[i]<2*Y+1:
      if ydp[i][j+updw[i]]==1:ydp[i+1][j]=1
if xdp[ypossi][x+X]==1 and ydp[tpossi][y+Y]==1:
  print("Yes")
else: print("No")

Submission status: Runtime Error

Solution code:
S=input()
S=S[:len(S)-1]
s=list(S)
x,y=map(int,input().split())
fora=0
side=[]
updw=[]
while s[0]=="F":
  fora+=1
  s.pop(0)
  if len(s)==0: break
flag=1#1のとき横向き、-1のときたて向き
step=0
while s:
  if s[0]=="T":
    s.pop(0)
    if flag==-1: updw+=[step]
    else: side+=[step]
    flag=flag*(-1)
    step=0
  else:
    s.pop(0)
    step+=1
    if len(s)==0:
      if flag==-1: updw+=[step]
      else: side+=[step]
ypossi=len(side)
tpossi=len(updw)
X=sum(side)+fora
Y=sum(updw)
xdp=[[0 for i in range(2*X+1)] for j in range(ypossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
xdp[0][fora+X]=1 
for i in range(ypossi):
  for j in range(2*X+1):
    if j-side[i]>=0:
      if xdp[i][j-side[i]]==1:xdp[i+1][j]=1
    if j+side[i]<2*X+1:
      if xdp[i][j+side[i]]==1:xdp[i+1][j]=1
        
ydp=[[0 for i in range(2*Y+1)] for j in range(tpossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
ydp[0][Y]=1 
for i in range(tpossi):
  for j in range(2*Y+1):
    if j-updw[i]>=0:
      if ydp[i][j-updw[i]]==1:ydp[i+1][j]=1
    if j+updw[i]<2*Y+1:
      if ydp[i][j+updw[i]]==1:ydp[i+1][j]=1
if xdp[ypossi][x+X]==1 and ydp[tpossi][y+Y]==1:
  print("Yes")
else: print("No")

Submission status: Runtime Error

Solution code:
S=input()
S=S[:len(S)-1]
s=list(S)
x,y=map(int,input().split())
fora=0
side=[]
updw=[]
while s[0]=="F":
  fora+=1
  s.pop(0)
flag=1#1のとき横向き、-1のときたて向き
step=0
while s:
  if s[0]=="T":
    s.pop(0)
    if flag==-1: updw+=[step]
    else: side+=[step]
    flag=flag*(-1)
    step=0
  else:
    s.pop(0)
    step+=1
    if len(s)==0:
      if flag==-1: updw+=[step]
      else: side+=[step]
ypossi=len(side)
tpossi=len(updw)
xdp=[[0 for i in range(2*len(S)+1)] for j in range(ypossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
xdp[0][fora+len(S)]=1 
for i in range(ypossi):
  for j in range(2*len(S)+1):
    if j-side[i]>=0:
      if xdp[i][j-side[i]]==1:xdp[i+1][j]=1
    if j+side[i]<2*len(S)+1:
      if xdp[i][j+side[i]]==1:xdp[i+1][j]=1
        
ydp=[[0 for i in range(2*len(S)+1)] for j in range(tpossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
ydp[0][len(S)]=1 
for i in range(tpossi):
  for j in range(2*len(S)+1):
    if j-updw[i]>=0:
      if ydp[i][j-updw[i]]==1:ydp[i+1][j]=1
    if j+updw[i]<2*len(S)+1:
      if ydp[i][j+updw[i]]==1:ydp[i+1][j]=1
if xdp[ypossi][x+len(S)]==1 and ydp[tpossi][y+len(S)]==1:
  print("Yes")
else: print("No")

Submission status: Runtime Error

Solution code:
S=str(input())
s=list(S)
x,y=map(int,input().split())
fora=0
side=[]
updw=[]
while s[0]=="F":
  fora+=1
  s.pop(0)
flag=1#1のとき横向き、-1のときたて向き
step=0
while s:
  if s[0]=="T":
    s.pop(0)
    if flag==-1: updw+=[step]
    else: side+=[step]
    flag=flag*(-1)
    step=0
  else:
    s.pop(0)
    step+=1
    if len(s)==0:
      if flag==-1: updw+=[step]
      else: side+=[step]
ypossi=len(side)
tpossi=len(updw)
xdp=[[0 for i in range(2*len(S)+1)] for j in range(ypossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
xdp[0][fora+len(S)]=1 
for i in range(ypossi):
  for j in range(2*len(S)+1):
    if j-side[i]>=0:
      if xdp[i][j-side[i]]==1:xdp[i+1][j]=1
    if j+side[i]<2*len(S)+1:
      if xdp[i][j+side[i]]==1:xdp[i+1][j]=1
        
ydp=[[0 for i in range(2*len(S)+1)] for j in range(tpossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
ydp[0][len(S)]=1 
for i in range(tpossi):
  for j in range(2*len(S)+1):
    if j-updw[i]>=0:
      if ydp[i][j-updw[i]]==1:ydp[i+1][j]=1
    if j+updw[i]<2*len(S)+1:
      if ydp[i][j+updw[i]]==1:ydp[i+1][j]=1
if xdp[ypossi][x+len(S)]==1 and ydp[tpossi][y+len(S)]==1:
  print("Yes")
else: print("No")

Submission status: Runtime Error

Solution code:
import sys
S=str(input())
s=list(S)
x,y=map(int,input().split())
fora=0
side=[]
updw=[]
side_p=[]
updw_p=[]
while s[0]=="F":
  fora+=1
  s.pop(0)
flag=1#1のとき横向き、-1のときたて向き
step=0
while s:
  if s[0]=="T":
    s.pop(0)
    if flag==-1: updw+=[step]
    else: side+=[step]
    flag=flag*(-1)
    step=0
  else:
    s.pop(0)
    if len(s)==0:
      if flag==-1: updw+=[step]
      else: side+=[step]
    step+=1
ypossi=len(side)
tpossi=len(updw)
xdp=[[0 for i in range(2*len(S)+1)] for j in range(ypossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
xdp[0][fora+len(S)]=1 
for i in range(ypossi):
  for j in range(2*len(S)+1):
    if j-side[i]>=0:
      if xdp[i][j-side[i]]==1:xdp[i+1][j]=1
    if j+side[i]<2*len(S)+1:
      if xdp[i][j+side[i]]==1:xdp[i+1][j]=1
        
ydp=[[0 for i in range(2*len(S)+1)] for j in range(tpossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
ydp[0][len(S)]=1 
for i in range(tpossi):
  for j in range(2*len(S)+1):
    if j-updw[i]>=0:
      if ydp[i][j-updw[i]]==1:ydp[i+1][j]=1
    if j+updw[i]<2*len(S)+1:
      if ydp[i][j+updw[i]]==1:ydp[i+1][j]=1
if xdp[ypossi][x+len(S)]==1 and ydp[tpossi][y+len(S)]==1:
  print("Yes")
else: print("No")

Submission status: Runtime Error

Solution code:
s = input().strip()
gx, gy = map(int, (input().split()))

flag = False

def dd(x, y, d, s):
    global flag
    if len(s) == 0:
        if x == gx and y == gy:
            flag = True
    else:
        if s[0] == 'F':
            if d == 0:
                dd(x+1, y, d, s[1:])
            elif d == 1:
                dd(x, y+1, d, s[1:])
            elif d == 2:
                dd(x-1, y, d, s[1:])
            else:
                dd(x, y-1, d, s[1:])
        elif s[0] == 'T':
            dd(x, y, (d+1)%4, s[1:])
            dd(x, y, (d-1)%4, s[1:])
dd(0, 0, 0, s)
if flag:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import copy

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

#少なくとも、右にx,↑にy進まなきゃいけない
# Fはくっつけられる
# s < 8000 よって N^2くらいならok
# Tが1回→左右 2回→前か後ろ 3回→左右
# この性質から、左右は左右のみで考えればいい
# x方向の数字N個をつかって、xを作成する 足し引きのみ 2^N xを加えて0にできるかどうか

s += "T"

now = 1
# 1はx方向、-1はy方向とする
start = 0
go = 0
x = []
y = []
for i in s:
    if i == "T":
        if start == 0:
            X = X - go
            go = 0
            start = 1
        else:
            if go != 0:
                if now == 1:
                    x.append(go)
                else:
                    y.append(go)
                go = 0
        now *= -1
    if i == "F":
        go += 1
x.sort()
y.sort()
x = x[::-1]
y = y[::-1]
X = abs(X)
Y = abs(Y)
x_use = sum(x) - X
y_use = sum(y) - Y
if x_use % 2 == 1 or y_use % 2 == 1 or x_use < 0 or y_use < 0:
    print("No")
    exit()
x_use = x_use//2
y_use = y_use//2


def solve(integer_list, target_sum,  i=0, sum=0):
    if sum > target_sum:
        return False
    if sum == target_sum:
        return True
    if i == len(integer_list):
        return sum == target_sum
    if (solve(integer_list, target_sum, i + 1, sum)):
        return True
    if (solve(integer_list, target_sum, i + 1, sum + integer_list[i])):
        return True
    return False

if solve(x, x_use) and solve(y, y_use):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

move = s.split('T')
yoko, tate = [], []
for i in range(len(move)):
    if i % 2 == 0:
        yoko.append(len(move[i]))
    else:
        tate.append(len(move[i]))


class DFS:
    def __init__(self, arr, start, goal):
        self.arr = arr
        self.start = start
        self.goal = goal
        self.offset = sum(arr) + 1
        self.dp = [[False for _ in range(self.offset * 2 + self.start)] for _ in range(len(arr) + 1)]
        self.dp[0][self.offset + self.start] = True

    def solve(self):
        # return self.dfs(0, 0) == self.goal
        if len(self.dp[0]) <= self.offset + self.goal:
            return False  # too far
        self.solve_dp()
        return self.dp[len(self.arr)][self.offset + self.goal]

    def solve_dp(self):
        for i in range(len(self.arr)):
            for j in range(len(self.dp[i])):
                if self.dp[i][j]:
                    self.dp[i + 1][j + self.arr[i]] = True
                    self.dp[i + 1][j - self.arr[i]] = True

    # def dfs(self, i, pos):
    #     if i == len(self.arr):
    #         return pos
    #     ret1 = self.dfs(i + 1, pos + self.arr[i])
    #     if ret1 == self.goal:
    #         return ret1
    #     ret2 = self.dfs(i + 1, pos - self.arr[i])
    #     return ret2

start = yoko[0]
yoko = yoko[1:]
end_in_x = DFS(yoko, start, x).solve()
end_in_y = DFS(tate, 0, y).solve()
ans = 'Yes' if end_in_x and end_in_y else 'No'
print(ans)

Submission status: Runtime Error

Solution code:
S_ = input()
S = []
for i in S_:
    S.append(i)
S.append("T")
x, y = map(int, input().split())
x_array = []
y_array = []
isX = True
cnt = 0

def x_canArrive(rob_x, i):
    if i == len(x_array):
        if rob_x == x:
            return True
        else:
            return False
    else:
        if x_canArrive(rob_x + x_array[i], i + 1) or x_canArrive(rob_x - x_array[i], i + 1):
            return True
        else:
            return False
def y_canArrive(rob_y, i):
    if i == len(y_array):
        if rob_y == y:
            return True
        else:
            return False
    else:
        if y_canArrive(rob_y + y_array[i], i + 1) or y_canArrive(rob_y - y_array[i], i + 1):
            return True
        else:
            return False

for i in S:
    if i == "T":
        if isX and cnt != 0:
            x_array.append(cnt)
        elif not(isX) and cnt != 0:
            y_array.append(cnt)
        cnt = 0
        isX = not(isX)
    else:
        cnt += 1
if x_canArrive(0, 0) and y_canArrive(0, 0):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

move = s.split('T')
yoko, tate = [], []
for i in range(len(move)):
    if i % 2 == 0:
        yoko.append(len(move[i]))
    else:
        tate.append(len(move[i]))


class DFS:
    def __init__(self, arr, goal):
        self.arr = arr
        self.goal = goal
        self.max_len = sum(arr)
        self.dp = [[False for _ in range(self.max_len * 2 + 2)] for _ in range(len(arr) + 1)]
        self.dp[0][self.max_len] = True

    def solve(self):
        # return self.dfs(0, 0) == self.goal
        self.solve_dp()
        return self.dp[len(self.arr)][self.max_len + self.goal]

    def solve_dp(self):
        for i in range(len(self.arr)):
            for j in range(len(self.dp[i])):
                if self.dp[i][j]:
                    self.dp[i + 1][j + self.arr[i]] = True
                    self.dp[i + 1][j - self.arr[i]] = True

    def dfs(self, i, pos):
        if i == len(self.arr):
            return pos
        ret1 = self.dfs(i + 1, pos + self.arr[i])
        if ret1 == self.goal:
            return ret1
        ret2 = self.dfs(i + 1, pos - self.arr[i])
        return ret2


end_in_x = DFS(yoko, x).solve()
end_in_y = DFS(tate, y).solve()
ans = 'Yes' if end_in_x and end_in_y else 'No'
print(ans)

Submission status: Runtime Error

Solution code:
import copy

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

#少なくとも、右にx,↑にy進まなきゃいけない
# Fはくっつけられる
# s < 8000 よって N^2くらいならok
# Tが1回→左右 2回→前か後ろ 3回→左右
# この性質から、左右は左右のみで考えればいい
# x方向の数字N個をつかって、xを作成する 足し引きのみ 2^N xを加えて0にできるかどうか

s += "T"

now = 1
# 1はx方向、-1はy方向とする
start = 0
go = 0
x = []
y = []
for i in s:
    if i == "T":
        if start == 0:
            X = X - go
            go = 0
            start = 1
        else:
            if go != 0:
                if now == 1:
                    x.append(go)
                else:
                    y.append(go)
                go = 0
        now *= -1
    if i == "F":
        go += 1

X = abs(X)
Y = abs(Y)
x_use = sum(x) - X
y_use = sum(y) - Y
if x_use % 2 == 1 or y_use % 2 == 1 or x_use < 0 or y_use < 0:
    print("No")
    exit()
x_use = x_use//2
y_use = y_use//2


def solve(integer_list, target_sum,  i=0, sum=0):
    if sum > target_sum:
        return False
    if i == len(integer_list):
        return sum == target_sum
    if (solve(integer_list, target_sum, i + 1, sum)):
        return True
    if (solve(integer_list, target_sum, i + 1, sum + integer_list[i])):
        return True
    return False

if solve(x, x_use) and solve(y, y_use):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import copy

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

#少なくとも、右にx,↑にy進まなきゃいけない
# Fはくっつけられる
# s < 8000 よって N^2くらいならok
# Tが1回→左右 2回→前か後ろ 3回→左右
# この性質から、左右は左右のみで考えればいい
# x方向の数字N個をつかって、xを作成する 足し引きのみ 2^N xを加えて0にできるかどうか

s += "T"

now = 1
# 1はx方向、-1はy方向とする
start = 0
go = 0
x = []
y = []
for i in s:
    if i == "T":
        if start == 0:
            X = X - go
            go = 0
            start = 1
        else:
            if go != 0:
                if now == 1:
                    x.append(go)
                else:
                    y.append(go)
                go = 0
        now *= -1
    if i == "F":
        go += 1

X = abs(X)
Y = abs(Y)
x_use = sum(x) - X
y_use = sum(y) - Y
if x_use % 2 == 1 or y_use % 2 == 1 or x_use < 0 or y_use < 0:
    print("No")
    exit()
x_use = x_use//2
y_use = y_use//2


def solve(integer_list, target_sum,  i=0, sum=0):
    if sum > target_sum:
        False
    if i == len(integer_list):
        return sum == target_sum
    if (solve(integer_list, target_sum, i + 1, sum)):
        return True
    if (solve(integer_list, target_sum, i + 1, sum + integer_list[i])):
        return True
    return False

if solve(x, x_use) and solve(y, y_use):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import copy

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

#少なくとも、右にx,↑にy進まなきゃいけない
# Fはくっつけられる
# s < 8000 よって N^2くらいならok
# Tが1回→左右 2回→前か後ろ 3回→左右
# この性質から、左右は左右のみで考えればいい
# x方向の数字N個をつかって、xを作成する 足し引きのみ 2^N xを加えて0にできるかどうか

s += "T"

now = 1
# 1はx方向、-1はy方向とする
start = 0
go = 0
x = []
y = []
for i in s:
    if i == "T":
        if start == 0:
            X - go
            go = 0
            start = 1
        else:
            if go != 0:
                if now == 1:
                    x.append(go)
                else:
                    y.append(go)
                go = 0
        now *= -1
    if i == "F":
        go += 1

X = abs(X)
Y = abs(Y)
x_use = sum(x) - X
y_use = sum(y) - Y
if x_use % 2 == 1 or y_use % 2 == 1 or x_use < 0 or y_use < 0:
    print("No")
    exit()
x_use = x_use//2
y_use = y_use//2


def solve(integer_list, target_sum,  i=0, sum=0):
    if sum > target_sum:
        False
    if i == len(integer_list):
        return sum == target_sum
    if (solve(integer_list, target_sum, i + 1, sum)):
        return True
    if (solve(integer_list, target_sum, i + 1, sum + integer_list[i])):
        return True
    return False

if solve(x, x_use) and solve(y, y_use):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import copy

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

#少なくとも、右にx,↑にy進まなきゃいけない
# Fはくっつけられる
# s < 8000 よって N^2くらいならok
# Tが1回→左右 2回→前か後ろ 3回→左右
# この性質から、左右は左右のみで考えればいい
# x方向の数字N個をつかって、xを作成する 足し引きのみ 2^N xを加えて0にできるかどうか

s += "T"

now = 1
# 1はx方向、-1はy方向とする
go = 0
x = []
y = []
for i in s:
    if i == "T":
        if go != 0:
            if now == 1:
                x.append(go)
            else:
                y.append(go)
            go = 0
        now *= -1
    if i == "F":
        go += 1

X = abs(X)
Y = abs(Y)
x_use = sum(x) - X
y_use = sum(y) - Y
if x_use % 2 == 1 or y_use % 2 == 1 or x_use < 0 or y_use < 0:
    print("No")
    exit()
x_use = x_use//2
y_use = y_use//2


def solve(integer_list, target_sum,  i=0, sum=0):
    if sum > target_sum:
        False
    if i == len(integer_list):
        return sum == target_sum
    if (solve(integer_list, target_sum, i + 1, sum)):
        return True
    if (solve(integer_list, target_sum, i + 1, sum + integer_list[i])):
        return True
    return False

if solve(x, x_use) and solve(y, y_use):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = [len(x) for x in input().split('T')]
x, y = map(int, input().split())
len_s = len(s)
sx = [s[i] for i in range(len_s) if i % 2 == 0]
sy = [s[i] for i in range(len_s) if i % 2 == 1]

x -= sx[0]
sx = sx[1:]



def is_reachable(p, s):
    origin = 8
    if origin+p < 0:
        return False
        
    n = len(s)
    reachable = [[False for _ in range(origin * 2 + 1)] for i in range(n + 2)]
    reachable[0][origin] = True

    for i in range(n):
        for j in range(origin * 2 + 1):
            if not reachable[i][j]:
                continue
            if j - s[i] >= 0:
                reachable[i + 1][j - s[i]] = True
            if j + s[i] <= origin * 2:
                reachable[i + 1][j + s[i]] = True
    return reachable[n][p + origin] or reachable[n][-p + origin]


if is_reachable(x, sx) and is_reachable(y, sy):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

move = s.split('T')
yoko, tate = [], []
for i in range(len(move)):
    if i % 2 == 0:
        yoko.append(len(move[i]))
    else:
        tate.append(len(move[i]))


class DFS:
    def __init__(self, arr, goal):
        self.arr = arr
        self.goal = goal
        # self.memo = [[-1 for _ in range(8000)] for _ in range(len(arr))]

    def solve(self):
        return self.dfs(0, 0) == self.goal

    def dfs(self, i, pos):
        if i == len(self.arr):
            return pos
        # if memo[i][pos] > -1:
        #     return memo[i][pos]
        ret1 = self.dfs(i + 1, pos + self.arr[i])
        if ret1 == self.goal:
            return ret1
        ret2 = self.dfs(i + 1, pos - self.arr[i])
        return ret2

end_in_x = DFS(yoko, x).solve()
end_in_y = DFS(tate, y).solve()
ans = 'Yes' if end_in_x and end_in_y else 'No'
print(ans)

Submission status: Runtime Error

Solution code:
s=input()+"T"
x,y=[int(i) for i in input().split()]


dx=[]
dy=[]

dir_is_X=True
step=0
for char in s:
        if char=='F':
                step+=1
        else:
                if dir_is_X:
                        dx.append(step)
                        dir_is_X=False
                        step=0
                else:
                        dy.append(step)
                        step=0
                        dir_is_X=True
#print(dx)
#print(dy)
bpos=5 #原点の位置
dpX=[[False for j in range(bpos*2+1)] for i in range(len(dx)+1)]
dpY=[[False for j in range(bpos*2+1)] for i in range(len(dy)+1)]

#10^7なら行けるっしょ
dpX[0][bpos]=True
dpY[0][bpos]=True

for i in range(len(dx)):
        for j in range(bpos*2+1):
                if dpX[i][j]:
                        dpX[i+1][j-dx[i]]=True
                        dpX[i+1][j+dx[i]]=True
for i in range(len(dy)):
        for j in range(bpos*2+1):
                if dpY[i][j]:
                        dpY[i+1][j-dy[i]]=True
                        dpY[i+1][j+dy[i]]=True
#print()
#for nums in dpX:
#       print(nums)
#rint()
#       print(nums)
if dpX[len(dx)][bpos+x] and dpY[len(dy)][bpos+y]:
        print("Yes")
else:
        print("No")