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:
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))

def move_dp(mlis):
    posi = [[0 for i in range(8001)] for j in range(len(mlis) + 1)]
    posi[0][4000] = 1
    #print(len(posi), len(posi[0]))
    for i in range(len(mlis)):
        mov = mlis[i]
        #   print(posi[i][3990:4020])

        for j in range(len(posi[i])):
            if posi[i][j] == 1:
                posi[i + 1][j + mov] = 1
                posi[i + 1][j - mov] = 1

    return posi[-1]

s = input()
x, y = getNM()

slis = s.split("T")
initx = len(slis[0])


if len(slis) < 2:
    xlis = []
else:
    xlis = [len(slis[i]) for i in range(len(slis)) if i%2 == 0][1:]
ylis = [len(slis[i]) for i in range(len(slis)) if i%2 == 1]

xpos = move_dp(xlis)
ypos = move_dp(ylis)

#print(xpos[3990:4020])
#print(ypos[3990:4220])


if xpos[4000-initx+x] == 1 and ypos[4000+y] == 1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))

def move_dp(mlis):
    posi = [[0 for i in range(8001)] for j in range(len(mlis) + 1)]
    posi[0][4000] = 1
    #print(len(posi), len(posi[0]))
    for i in range(len(mlis)):
        mov = mlis[i]
        #   print(posi[i][3990:4020])

        for j in range(len(posi[i])):
            if posi[i][j] == 1:
                posi[i + 1][j + mov] = 1
                posi[i + 1][j - mov] = 1

    return posi[-1]

s = input()
x, y = getNM()

slis = s.split("T")
initx = len(slis[0])

xlis = [len(slis[i]) for i in range(len(slis)) if i%2 == 0][1:]
ylis = [len(slis[i]) for i in range(len(slis)) if i%2 == 1]

xpos = move_dp(xlis)
ypos = move_dp(ylis)

#print(xpos[3990:4020])
#print(ypos[3990:4220])


if xpos[4000-initx+x] == 1 and ypos[4000+y] == 1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = input()+'T'
x,y=map(int,input().split())
di = 0
count = 0
xlis = []
ylis = []
for charas in s:
  if charas == 'F':
    count += 1
  else:
    if count>0:
      if di%2==0:
        xlis.append(count)
      else:
        ylis.append(count)
      count = 0
    di += 1
if xlis==[]:
  xlis.append(0)
if ylis==[]:
  ylis.append(0)
def xdp(n,x0):
  if n==1 and x0==xlis[0]:
    return True
  elif n==1:
    return False
  else:
    return xdp(n-1,x0-xlis[n-1]) or xdp(n-1,x0+xlis[n-1])
def ydp(n,y0):
  if n==1 and abs(y0)==ylis[0]:
    return True
  elif n==1:
    return False
  else:
    return ydp(n-1,y0-ylis[n-1]) or ydp(n-1,y0+ylis[n-1])
def ans():
  return xdp(len(xlis),x) and ydp(len(ylis),y)
if ans() == True:
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

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

import sys
from itertools import islice

def reachable(steps, x):
    m = len(steps)
    if m == 0:
        return x == 0
    n = sum(steps) + 1
    if n <= x:
        return False
    dp = [[False] * n for _ in range(m)]
    dp[0][steps[0]] = True
    for i, step in enumerate(islice(steps, 1, None)):
        for j in range(n):
            if dp[i][j] == True:
                if j + step < n:
                    dp[i + 1][j + step] = True
                if j - step >= 0:
                    dp[i + 1][j - step] = True
    return dp[-1][x]


def main():
    s = sys.stdin.readline().strip()
    x, y = map(int, sys.stdin.readline().split())

    i = s.find('T')
    if i > 0:
        x -= i
    else:
        i = 0

    xsteps = []
    ysteps = []
    cnt = 0
    nturns = 0
    for c in islice(s, i, None):
        if c == 'F':
            cnt += 1
            continue
        if cnt > 0:
            if nturns % 2 == 0:
                xsteps.append(cnt)
            else:
                ysteps.append(cnt)
            cnt = 0
        nturns += 1
    else:
        if cnt > 0:
            if nturns % 2 == 0:
                xsteps.append(cnt)
            else:
                ysteps.append(cnt)

    if reachable(xsteps, abs(x)) == True and reachable(ysteps, abs(y)) == True:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()
amnesia@amnesia

Submission status: Runtime Error

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

h, v = [], []
for i, si in enumerate(s):
    if i % 2 == 0:
        h.append(len(si))
    else:
        v.append(len(si))

def search(move, goal, vertical):
    if vertical:
        goal -= move.pop(0)

    move.sort(reverse=True)
    for m in move:
        if goal > 0:
            goal -= m
        else:
            goal += m
    return goal == 0

if search(h, x, True) and search(v, y, True):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
*s,=map(len,input().split("T"))
n=len(s)
ix,iy=map(int,input().split())
state=[(0,1),(1,0),(-1,0),(0,-1)]

def chk(x,y,turn,pos):
    if pos<n:
        tx,ty=turn
        nx,ny=x+tx*s[pos],y+ty*s[pos]
        if turn==(1,0) or turn==(-1,0):
            a=chk(nx,ny,(0,1),pos+1)
            b=chk(nx,ny,(0,-1),pos+1)
        elif turn==(0,1) or turn==(0,-1):
            a=chk(nx,ny,(1,0),pos+1)
            b=chk(nx,ny,(-1,0),pos+1)
        if a or b:
            return True
        else:
            return False         
    else:
        if x==ix and y==iy:
            return True
        else:
            return False

if chk(0,0,(1,0),0):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

S = input()
Xans,Yans = inpl()

Xmove = []
Ymove = []

flag = True
tmp = 0
for s in S+'T':
	if s == 'F':
		tmp += 1
	else:
		if flag:
			Xmove.append(tmp)
		else:
			Ymove.append(tmp)
		tmp = 0
		flag = not flag

if len(Xmove) == 0:
	if Xans != 0:
		print('No')
		sys.exit()
else:
	Xsum = sum(Xmove)
	if (Xsum+Xans)%2 == 1:
		print('No')
		sys.exit()
	else:
		Xpos = (Xsum+Xans)//2
		dp = [0]*(Xpos+1)
		dp[0] = 1
		for x in Xmove:
			for i in range(Xpos,x-1,-1):
				dp[i] = dp[i-x]
			if dp[-1] == 1:
				break
		else:
			print('No')
			sys.exit()


if len(Ymove) == 0:
	if Yans != 0:
		print('No')
		sys.exit()
else:
	Ysum = sum(Ymove)
	if (Ysum+Yans)%2 == 1:
		print('No')
		sys.exit()
	else:
		Ypos = (Ysum+Yans)//2
		dp = [0]*(Ypos+1)
		dp[0] = 1
		for y in Ymove:
			for i in range(Ypos,y-1,-1):
				dp[i] = dp[i-y]

			if dp[-1] == 1:
				break
		else:
			print('No')
			sys.exit()

print('Yes')

Submission status: Runtime Error

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

S = input()
Xans,Yans = inpl()

Xmove = []
Ymove = []

flag = True
tmp = 0
for s in S+'T':
	if s == 'F':
		tmp += 1
	else:
		if flag:
			Xmove.append(tmp)
		else:
			Ymove.append(tmp)
		tmp = 0
		flag = not flag


Xsum = sum(Xmove)

if (Xsum+Xans)%2 == 1:
	print('No')
	sys.exit()
else:
	Xpos = (Xsum+Xans)//2
	dp = [0]*(Xpos+1)
	dp[0] = 1
	for x in Xmove:
		for i in range(Xpos,x-1,-1):
			dp[i] = dp[i-x]

		if dp[-1] == 1:
			break
	else:
		print('No')
		sys.exit()

Ysum = sum(Ymove)
if (Ysum+Yans)%2 == 1:
	print('No')
	sys.exit()
else:
	Ypos = (Ysum+Yans)//2
	dp = [0]*(Ypos+1)
	dp[0] = 1
	for y in Ymove:
		for i in range(Ypos,y-1,-1):
			dp[i] = dp[i-y]

		if dp[-1] == 1:
			break
	else:
		print('No')
		sys.exit()

print('Yes')

Submission status: Runtime Error

Solution code:
s = input()
x,y = (int(i) for i in input().split())
f,l,dx,now,num = s.count("T"),len(s),True,0,0
ax = [[0 for i in range((l-f)*2+1)] for i in range((f+2)//2+1)]
ay = [[0 for i in range((l-f)*2+1)] for i in range(f//2+1)]
ax[0][l-f],ay[0][l-f],s = 1,1,s+"T"
for i in range(l+1):
	if s[i]=="F": num+=1
	elif dx:
		for j in range((l-f)*2+1):
			if ax[now][j]==1:
				if j-num>=0: ax[now+1][j-num]=1
				if j+num<(l-f)*2+1: ax[now+1][j+num]=1
		dx,num = False,0
	else:
		for j in range((l-f)*2+1):
			if ay[now][j]==1:
				if j-num>=0: ay[now+1][j-num]=1
				if j+num<(l-f)*2+1: ay[now+1][j+num]=1
		now,dx,num = now+1,True,0
if ax[-1][l-f+x]==1 and ay[-1][l-f+y]==1: print("Yes")
else: print("No")

Submission status: Runtime Error

Solution code:
def main():
  s = input()
  x, y = map(int, input().split())
  lens = len(s)
  ind = 0
  if "T" in s:
    ind = s.index("T")
    x -= ind
  else:
    ind = lens
    x -= lens
  x_lst = []
  y_lst = []
  direct = 0
  while ind < lens:
    acc = 0
    if s[ind] == "F":
      while ind < lens and s[ind] == "F":
        ind += 1
        acc += 1
      if direct == 0:
        x_lst.append(acc)
      else:
        y_lst.append(acc)
  
    elif s[ind] == "T":
      while ind < lens and s[ind] == "T":
        ind += 1
        acc += 1
  
      direct = (direct + acc) % 2
  
  sumx = sum(x_lst)
  sumy = sum(y_lst)
  if sumx < x or (sumx - x) % 2 or sumy < y or (sumy - y) % 2:
    print("No")
  else:
    target_x = (sumx - x) // 2 + x
    target_y = (sumy - y) // 2 + y
    canx = [False] * (sumx + 1)
    canx[0] = True
    cany = [False] * (sumy + 1)
    cany[0] = True
  
    break_flag = False
    for v in x_lst:
      for i in range(sumx - v + 1):
        if canx[i]:
          canx[i + v] = True
          if i + v == target_x:
            break_flag = True
            break
      if break_flag:
        break
    
    break_flag = False
    for v in y_lst:
      for i in range(sumy - v + 1):
        if cany[i]:
          cany[i + v] = True
          if i + v == target_y:
            break_flag = True
            break
      if break_flag:
        break
  
    if canx[target_x] and cany[target_y]:
      print("Yes")
    else:
      print("No")

main()

Submission status: Runtime Error

Solution code:
s=input().strip()
x,y=map(int,input().split())
sl=[len(i) for i in s.split('T')]
x0,y0=sl[0],0

answers={}
def search(xx,yy,k,isUD):
    if (xx,yy,k) in answers:
        return answers[(xx,yy,k)]
    if k == len(sl):
        ans=(xx,yy)==(x,y)
    else:
        lng=sl[k]
        # D or L
        llr=(lng if not isUD else 0)
        lud=(lng if isUD else 0)
        d_l = search(xx-llr,yy-lud,k+1, not isUD)
        u_r = search(xx+llr,yy+lud,k+1, not isUD)
        ans = d_l or u_r
    answers[(xx,yy,k)]=ans
    return ans
print('Yes' if search(x0,y0,1,True) else 'No')

Submission status: Runtime Error

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

movex = []
movey = []

for i, t in enumerate(s):
    if i % 2 == 0:
        movex.append(len(t))
    else:
        movey.append(len(t))


def t_dfs(move, target, now):
    #print(move, target, now)
    if len(move) == 0:
        if target == now:
            return True
        else:
            return False

    return t_dfs(move[1:], target, now+move[0]) or t_dfs(move[1:], target, now-move[0])


if t_dfs(movex, x, 0) and t_dfs(movey, y, 0):
    print("YES")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = input()
tmp = list(map(int, input().split()))
x,y = tmp[0],tmp[1]
xy = [[],[]]
j = 0
k = 0
for i in s:
    if i == "F":
        j += 1
    else:
        xy[k].append(j)
        j = 0
        k = (k + 1) % 2
if j != 0:
    xy[k].append(j)
if s[0] == "F":
    x -= xy[0][0]
    del xy[0][0]
sumx = sum(xy[0]) - x
sumy = sum(xy[1]) - y
if sumx % 2 or sumy % 2 or sumx < 0 or sumy< 0:
    print("No")
    quit()
else:
    sumx //= 2
    sumy //= 2

def dfs_x(i,s):
    if i == len(xy[0]):
        return (s == sumx)
    return(dfs_x(i+1,s+xy[0][i]) or dfs_x(i+1,s-xy[0][i]))

def dfs_y(i,s):
    if i == len(xy[1]):
        return (s == sumy)
    return(dfs_y(i+1,s+xy[1][i]) or dfs_y(i+1,s-xy[1][i]))

if dfs_x(0,0) and dfs_y(0,0):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = input()
tmp = list(map(int, input().split()))
x,y = tmp[0],tmp[1]
xy = [[],[]]
j = 0
k = 0
for i in s:
    if i == "F":
        j += 1
    else:
        xy[k].append(j)
        j = 0
        k = (k + 1) % 2
if j != 0:
    xy[k].append(j)
if s[0] == "F":
    x -= xy[0][0]
    del xy[0][0]
sumx = sum(xy[0]) - x
sumy = sum(xy[1]) - y
if sumx % 2 or sumy % 2 or sumx < 0 or sumy< 0:
    print("No")
    quit()
else:
    sumx //= 2
    sumy //= 2
def dfs_x(i,s):
    if i == len(xy[0]):
        return (s == sumx)
    if (dfs_x(i+1,s)):
        return True
    if (dfs_x(i+1,s+xy[0][i])):
        return True
    return False

def dfs_y(i,s):
    if i == len(xy[1]):
        return (s == sumy)
    if (dfs_y(i+1,s)):
        return True
    if (dfs_y(i+1,s+xy[1][i])):
        return True
    return False

if dfs_x(0,0) and dfs_y(0,0):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
S = list(S.split("T"))
x, y = map(int, input().split())

X_command = sorted([len(i) for i in S[::2]], reverse=True)
Y_command = sorted([len(i) for i in S[1::2]], reverse=True)

dp_x = [[False] * (sum(X_command)+1) for i in range(len(X_command))]
dp_y = [[False] * (sum(Y_command)+1) for i in range(len(Y_command))]

if X_command:
    dp_x[0][X_command[0]] = True
    for i in range(1, len(X_command)):
        for xi in range(sum(X_command)):
            if xi + X_command[i] >= N-1:
                continue
            if xi-X_command[i] >= 0:
                dp_x[i][xi] = dp_x[i-1][xi-X_command[i]] or dp_x[i-1][xi+X_command[i]]
            else:
                dp_x[i][xi] = dp_x[i-1][xi+X_command[i]]

if Y_command:
    dp_y[0][Y_command[0]] = True
    for i in range(1, len(Y_command)):
        for yi in range(sum(Y_command)):
            if yi + Y_command[i] >= N-1:
                continue
            if yi-Y_command[i] >= 0:
                dp_y[i][yi] = dp_y[i-1][yi-Y_command[i]] or dp_y[i-1][yi+Y_command[i]]
            else:
                dp_y[i][yi] = dp_y[i-1][yi+Y_command[i]]


x, y = max(x, -x), max(y, -y)

if sum(X_command) < x or sum(Y_command) < y:
    print("No")
    exit()
if dp_x[len(X_command)-1][x] and dp_y[len(Y_command)-1][y]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
S = list(S.split("T"))
x, y = map(int, input().split())

X_command = sorted([len(i) for i in S[::2]], reverse=True)
Y_command = sorted([len(i) for i in S[1::2]], reverse=True)

dp_x = [[False] * N for i in range(N)]
dp_y = [[False] * N for i in range(N)]

if X_command:
    dp_x[0][X_command[0]] = True
    for i in range(1, len(X_command)):
        for xi in range(N):
            if xi + X_command[i] >= N:
                continue
            if xi-X_command[i] >= 0:
                dp_x[i][xi] = dp_x[i-1][xi-X_command[i]] or dp_x[i-1][xi+X_command[i]]
            else:
                dp_x[i][xi] = dp_x[i-1][xi+X_command[i]]

if Y_command:
    dp_y[0][Y_command[0]] = True
    for i in range(1, len(Y_command)):
        for yi in range(N):
            if yi + Y_command[i] >= N:
                continue
            if yi-Y_command[i] >= 0:
                dp_y[i][yi] = dp_y[i-1][yi-Y_command[i]] or dp_y[i-1][yi+Y_command[i]]
            else:
                dp_y[i][yi] = dp_y[i-1][yi+Y_command[i]]


x, y = max(x, -x), max(y, -y)

if dp_x[len(X_command)-1][x] and dp_y[len(Y_command)-1][y]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
from collections import deque
def Move(xy_old):
   xy = xy_old
   vec = xy[2:4]
   if vec == [1, 0]:
      xy[0] += 1
   elif vec == [-1, 0]:
      xy[0] -= 1
   elif vec == [0, 1]:
      xy[1] += 1
   elif vec == [0, -1]:
      xy[1] -= 1
   xy[4] += 1
   return xy


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

   Fcount = 0
   for ss in s:
      if ss == "F":
         Fcount += 1
   if Fcount < (abs(x)+abs(y)):
      return "No"

   # BFS
   k = len(s)
   q = deque([[0,0,1,0,0]])
   while q!=deque([]):
      xy_now = q.popleft()
      now = xy_now[4]
      if (xy_now[0:2]==[x,y])and(now==k):
         return "Yes"
      elif now==k:
         continue
      else: #now != k
         if s[now] == "F":
            q.append(Move(xy_now))
         else:
            for vv in [1, -1]:
               if xy_now[2] == 0:
                  xy_next = xy_now
                  xy_next[2] = vv
                  xy_next[3] = 0
                  xy_next[4]+=1
                  q.append(xy_next)
               elif xy_now[3] == 0:
                  xy_next = xy_now
                  xy_next[3] = vv
                  xy_next[2] = 0
                  xy_next[4]+=1
                  q.append(xy_next)
   return "No"


print(main())

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

def possible(goal, move):
    if len(move) == 0:
        if goal == 0:
            return True
        else:
            return False
            
    sumup = sum(move)
    
    if (sumup+goal)%2 == 1:
        return False
    dp = [[False for j in range((goal+sumup)+1)] for i in range(len(move))]
    dp[0][0] = True
    dp[0][move[0]] = True
    
    for i in range(1, len(move)):
        for j in range((sumup+goal)//2+1):
            dp[i][j] = dp[i][j] or dp[i-1][j]
            if j >= move[i]:
                dp[i][j] = dp[i][j] or dp[i-1][j-move[i]]
                
    return dp[len(move)-1][(sumup+goal)//2]
    
 
if __name__ == '__main__':
    S = input()
    goalx,goaly = [int(i) for i in input().split()]

    xmove_ind = 0
    ymove_ind = 0
    dir_x = True
    count = 0
    xmove = []
    ymove = []
    
    for i in range(0, len(S)+1):
        if i == len(S) or S[i] == 'T' :
            if dir_x == True:
                if count > 0:
                    xmove.append(count)
            else:
                if count > 0:
                    ymove.append(count)
            count = 0
            dir_x = not dir_x
        else:
            count += 1
    
    #print(xmove)
    #print(ymove)
    
    if possible(abs(goaly) , ymove):
        if len(xmove) == 1:
            if goalx == xmove[0]:
                print("Yes")
            else:
                print("No")
        else:
            if possible(abs(goalx-xmove[0]), xmove[1:]):
                print("Yes")
            else:
                print("No")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

def possible(goal, move):
    if len(move) == 0:
        if goal == 0:
            return True
        else:
            return False
            
    sumup = sum(move)
    
    if (sumup+goal)%2 == 1:
        return False
    dp = [[False for j in range((goal+sumup)+1)] for i in range(len(move))]
    dp[0][0] = True
    dp[0][move[0]] = True
    
    for i in range(1, len(move)):
        for j in range((sumup+goal)//2+1):
            dp[i][j] = dp[i][j] or dp[i-1][j]
            if j >= move[i]:
                dp[i][j] = dp[i][j] or dp[i-1][j-move[i]]
                
    return dp[len(move)-1][(sumup+goal)//2]
    
 
if __name__ == '__main__':
    S = input()
    goalx,goaly = [int(i) for i in input().split()]

    xmove_ind = 0
    ymove_ind = 0
    dir_x = True
    count = 0
    xmove = []
    ymove = []
    
    for i in range(0, len(S)+1):
        if i == len(S) or S[i] == 'T' :
                if dir_x == True:
                    if count > 0:
                   		xmove.append(count)
                else:
                  	if count > 0:
                    	ymove.append(count)
                count = 0
                dir_x = not dir_x
        else:
            count += 1
    
    print(xmove)
    print(ymove)
    
    if possible(abs(goaly) , ymove):
        if len(xmove) == 1:
            if goalx == xmove[0]:
                print("Yes")
            else:
                print("No")
        else:
            if possible(abs(goalx-xmove[0]), xmove[1:]):
                print("Yes")
            else:
                print("No")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

def possible(goal, move):
    if len(move) == 0:
        if goal == 0:
            return True
        else:
            return False
            
    sumup = sum(move)
    
    if (sumup+goal)%2 == 1:
        return False
    dp = [[False for j in range((goal+sumup)+1)] for i in range(len(move))]
    dp[0][0] = True
    dp[0][move[0]] = True
    
    for i in range(1, len(move)):
        for j in range((sumup+goal)//2+1):
            dp[i][j] = dp[i][j] or dp[i-1][j]
            if j >= move[i]:
                dp[i][j] = dp[i][j] or dp[i-1][j-move[i]]
                
    return dp[len(move)-1][(sumup+goal)//2]
    
 
if __name__ == '__main__':
    S = input()
    goalx,goaly = [int(i) for i in input().split()]

    xmove_ind = 0
    ymove_ind = 0
    dir_x = True
    count = 0
    xmove = []
    ymove = []
    
    for i in range(0, len(S)+1):
        if i == len(S) or S[i] == 'T' :
            if count == 0:
                dir_x = not dir_x
            else:
                if dir_x == True:
                    xmove.append(count)
                else:
                    ymove.append(count)
                count = 0
                dir_x = not dir_x
        else:
            count += 1
    
    print(xmove)
    print(ymove)
    
    if possible(abs(goaly) , ymove):
        if len(xmove) == 1:
            if goalx == xmove[0]:
                print("Yes")
            else:
                print("No")
        else:
            if possible(abs(goalx-xmove[0]), xmove[1:]):
                print("Yes")
            else:
                print("No")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

def possible(goal, move):
    if len(move) == 0:
        if goal == 0:
            return True
        else:
            return False
            
    sumup = sum(move)
    
    if (sumup+goal)%2 == 1:
        return False
    
    dp = [[False for j in range((goal+sumup)//2+1)] for i in range(len(move))]
    dp[0][0] = True
    dp[0][move[0]] = True
    
    for i in range(1, len(move)):
        for j in range((sumup+goal)//2+1):
            dp[i][j] = dp[i][j] or dp[i-1][j]
            if j >= move[i]:
                dp[i][j] = dp[i][j] or dp[i-1][j-move[i]]
                
    return dp[len(move)-1][(sumup+goal)//2]
    
 
if __name__ == '__main__':
    S = input()
    goalx,goaly = [int(i) for i in input().split()]

    xmove_ind = 0
    ymove_ind = 0
    dir_x = True
    count = 0
    xmove = []
    ymove = []
    
    for i in range(0, len(S)+1):
        if i == len(S) or S[i] == 'T' :
            if count == 0:
                dir_x = not dir_x
            else:
                if dir_x == True:
                    xmove.append(count)
                else:
                    ymove.append(count)
                count = 0
                dir_x = not dir_x
        else:
            count += 1
    
    #print(xmove)
    #print(ymove)
    
    if possible(abs(goaly) , ymove):
        if len(xmove) == 1:
            if goalx == xmove[0]:
                print("Yes")
            else:
                print("No")
        else:
            if possible(abs(goalx-xmove[0]), xmove[1:]):
                print("Yes")
            else:
                print("No")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)

dir=[[1,0],[0,-1],[-1,0],[0,1]]
s=input()
X,Y=map(int,input().split())
log={}

def walk(x,y,direction,count):
	if (x,y,direction,count) in log:
		return log[(x,y,direction,count]
	if count==len(s):
		if x==X and y==Y:
			return True
		else: 
			return False
	if s[count]=="F":
		log[(x,y,direction,count)]=walk(d+dir[direction][0],y+dir[direction][1],direction,count+1)
		return log[(x,y,direction,count)]
	else:
		log[(x,y,direction,count)]=walk(x,y,(direction+1)%4,count+1) or walk(x,y,(direction-1+4)%4,count+1)
		return log[(x,y,direction,count)]

if walk(0,0,0,0)==True:
	print('Yes')
else:
	print('No')

Submission status: Runtime Error

Solution code:
dir=[[1,0],[0,-1],[-1,0],[0,1]]
s=input()
X,Y=map(int,input().split())
log={}

def walk(x,y,direction,count):
	if (x,y,direction,count) in log:
		return log[(x,y,direction,count]
	if count==len(s):
		if x==X and y==Y:
			return True
		else: 
			return False
	if s[count]=="F":
		log[(x,y,direction,count)]=walk(d+dir[direction][0],y+dir[direction][1],direction,count+1)
		return log[(x,y,direction,count)]
	else:
		log[(x,y,direction,count)]=walk(x,y,(direction+1)%4,count+1) or walk(x,y,(direction-1+4)%4,count+1)
		return log[(x,y,direction,count)]

if walk(0,0,0,0)==True:
	print('Yes')
else:
	print('No')

Submission status: Runtime Error

Solution code:
dir=[[1,0],[0,-1],[-1,0],[0,1]]
s=input()
X,Y=map(int,input().split())

def walk(x,y,direction,count):
	if count==len(s):
		if x==X and y==Y:
			return True
		else: 
			return False
	if s[count]=="F":
		return walk(x+dir[direction][0],y+dir[direction][1],direction,count+1)
	else:
		return walk(x,y,(direction+1)%4,count+1) or walk(x,y,(direction-1+4)%4,count+1)

if walk(0,0,0,0)==True:
	print('Yes')
else:
	print('No')

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 abs(p) == abs(lr_count[0]):
            return 1
        else:
            return 0
    else:
        return dlr(i-1,p+lr_count[i]) + dlr(i-1,p-lr_count[i])
    
def dud(i, p):
    global ud_count
    if i < 0:
        return 0
    if i == 0:
        if abs(p) == abs(ud_count[0]):
            return 1
        else:
            return 0
    else:
        return dud(i-1,p+ud_count[i]) + dud(i-1,p-ud_count[i])

for i in range(len(s)):
    if s[i] == 'T':
        if F_count == 0:
            pass
        elif 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 F_count == 0:
                pass
            if lr_check == True:
                lr_count.append(F_count)
            else:
                ud_count.append(F_count)


if lr_count == [] and ud_count == []:
    if F_count == x and 0 == y:
        print('Yes')
    else:
        print('No')
elif ud_count == []:
    if sum(lr_count) == x and 0 == y:
        print('Yes')
    else:
        print('No')
elif lr_count == []:
    if 0 == x and sum(ud_count) == 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:
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]) + dlr(i-1,p-lr_count[i])
    
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]) + dud(i-1,p-ud_count[i])

for i in range(len(s)):
    if s[i] == 'T':
        if F_count == 0:
            pass
        elif 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 F_count == 0:
                pass
            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:
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 F_count == 0:
            pass
        elif 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 F_count == 0:
                pass
            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')