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:
import math

s=list(input().split('T'))
sn=[]

for i in range(len(s)):
    sn.append(len(s[i]))

x, y = map(int,input().split(' '))
x = x-sn[0]

snx=[]
sny=[]

for i in range(2,len(sn),2):
    snx.append(sn[i])

for i in range(1,len(sn),2):
    sny.append(sn[i])

#X軸判定
xflg = 0
ansx=[]
prex=[0]
for i in range(len(snx)):
    tmpx=set()
    for j in prex:
        tmpx.add(j+snx[i])
        tmpx.add(j-snx[i])
    prex=tmpx

if x in tmpx:
    xflg = 1

#y軸判定
yflg = 0
prey=[0]
for i in range(len(sny)):
    tmpy=set()
    for j in prey:
        tmpy.add(j+sny[i])
        tmpy.add(j-sny[i])
    prey=tmpy

if y in tmpy:
    yflg = 1

if xflg == 1 and yflg == 1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import math

s=list(input().split('T'))
sn=[]

for i in range(len(s)):
    sn.append(len(s[i]))

x, y = map(int,input().split(' '))
x = x-sn[0]

snx=[]
sny=[]

for i in range(2,len(sn),2):
    snx.append(sn[i])

for i in range(1,len(sn),2):
    sny.append(sn[i])

#X軸判定
xflg = 0
ansx=[]
prex=[0]
for i in range(len(snx)):
    tmpx=set()
    for j in prex:
        tmpx.add(j+snx[i])
        tmpx.add(j-snx[i])
    prex=tmpx

if x in tmpx:
    xflg = 1

#y軸判定
yflg = 0
prey=[0]
for i in range(len(sny)):
    tmpy=set()
    for j in tmpy:
        tmpy.add(j+sny[i])
        tmpy.add(j-sny[i])
    prey=tmpy

if y in tmpy:
    yflg = 1

if xflg == 1 and yflg == 1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

import sys


def become_a(a, start, numbers):
    if numbers is None:
        return a == start
    if len(numbers) == 1:
        return a == start + numbers[0] or a == start - numbers[0]
    return become_a(a, start + numbers[0], numbers[1:]) or become_a(a, start - numbers[0],
                                                                    numbers[1:])


s = sys.stdin.readline().strip().split("T")
x, y = sys.stdin.readline().strip().split(" ")
x = int(x)
y = int(y)
move_all = [len(_s) for _s in s]
move_x = move_all[::2]
move_y = move_all[1::2] or None
if become_a(x, move_x[0], move_x[1:] or None) and become_a(y, 0, move_y):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

import sys
import numpy as np


def culc_pos(x, y, commands, pos=np.matrix([0, 0]), d=np.matrix([1, 0])):
    if len(commands) == 1:
        if not commands[0]:
            pos = pos + d
        return pos[0, 0] == x and pos[0, 1] == y
    if commands[0]:
        ccw = np.matrix([[0, -1], [1, 0]])
        cw = np.matrix([[0, 1], [-1, 0]])
        d1 = d * ccw
        d2 = d * cw
        return culc_pos(x, y, commands[1:], pos, d1) or culc_pos(x, y, commands[1:], pos, d2)
    else:
        pos = pos + d
        return culc_pos(x, y, commands[1:], pos, d)


s = sys.stdin.readline().strip()
x, y = sys.stdin.readline().strip().split(" ")
x = int(x)
y = int(y)
s_list = [_s == "T" for _s in list(s)]
if culc_pos(x, y, s_list):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

import sys
import numpy as np


def culc_pos(x, y, commands, pos=np.matrix([0, 0]), d=np.matrix([1, 0])):
    if len(commands) == 1:
        if commands[0]:
            return pos[0, 0] == x and pos[0, 1] == y
        else:
            pos = pos + d
            return pos[0, 0] == x and pos[0, 1] == y
    if commands[0]:
        ccw = np.matrix([[0, -1], [1, 0]])
        cw = np.matrix([[0, 1], [-1, 0]])
        d1 = d * ccw
        d2 = d * cw
        return culc_pos(x, y, commands[1:], pos, d1) or culc_pos(x, y, commands[1:], pos, d2)
    else:
        pos = pos+d
        return culc_pos(x, y, commands[1:], pos, d)


s = sys.stdin.readline().strip()
x, y = sys.stdin.readline().strip().split(" ")
x = int(x)
y = int(y)
s_list = [_s == "T" for _s in list(s)]
if culc_pos(x, y, s_list):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

s = list(map(len,input().split('T')))
x,y = list(map(int, input().split()))
x_steps = s[2::2]
y_steps = s[1::2]
x_steps.append(x-s[0])
y_steps.append(y)
#あとは、それぞれの和で0になる組み合わせを探すだけ
def rec(l,x):
    if l:
        return rec(l[1:],x+l[0]) or rec(l[1:],x-l[0])
    elif x == 0:
        return True
    else:
        return False
if rec(x_steps, 0) and rec(y_steps, 0):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s = input()
list_s = list(s)
l= input().split()
x = int(l[0])
y = int(l[1])

yes = False

def run(currentX, currentY, directionX, directionY, num, list_s):
    global yes
    if list_s[num] == "F":
        
        num += 1
        if directionX == 1:
            currentX += 1
        elif directionX == -1:
            currentX -= 1
        else:
            if directionY == 1:
                currentY += 1
            elif directionY == -1:
                currentY -= 1
        if num >= len(list_s):
            
            if currentX == x and currentY == y:
                yes = True
                
        else:
            run(currentX, currentY, directionX, directionY, num, list_s)
    elif list_s[num] == "T":
        num+=1
        if num >= len(list_s):
            if currentX == x and currentY == y:
                yes = True
        else:
            if directionX != 0: 
                run(currentX, currentY, 0, 1, num, list_s)
                run(currentX, currentY, 0, -1, num, list_s)
            else:
                run(currentX, currentY, 1, 0, num, list_s)
                run(currentX, currentY, -1, 0, num, list_s)

run(0,0,1, 0, 0, list_s)

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

Submission status: Runtime Error

Solution code:
z,*s=map(len,input().split('T'));l=sum(s);Y=1<<l;X=Y<<z
for t,u in zip(s[::2],s[1::2]+[0]):Y=Y>>t|Y<<t;X=X>>u|X<<u
x,y=map(int,input().split());print("Yes"*(X>>l+x&Y>>l+y&1)or"No")

Submission status: Runtime Error

Solution code:
z,*s=map(len,input().split('T')+['']);l=sum(s,0);Y=1<<l;X=Y<<z
for t,u in zip(s[::2],s[1::2]):Y=Y>>t|Y<<t;X=X>>u|X<<u
x,y=map(int,input().split());print("Yes"*(X>>l+x&Y>>l+y&1)or"No")

Submission status: Runtime Error

Solution code:
z,*s,=map(len,input().split('T')+['']);l=sum(s);Y=1<<l;X=Y<<z
for t,u in zip(s[::2],s[1::2]):Y=Y>>t|Y<<t;X=X>>u|X<<u
x,y=map(int,input().split());print("Yes"*(X>>l+x&Y>>l+y&1)or"No")

Submission status: Runtime Error

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


def part_sum0(integer_list, target_sum,  i=0, sum_=0):
    if i == len(integer_list):
        return sum_ == target_sum
    if (part_sum0(integer_list, target_sum, i + 1, sum_)):
        return True
    if (part_sum0(integer_list, target_sum, i + 1, sum_ + integer_list[i])):
        return True
    return False


fs = s.split('T')
f_num = [len(f) for f in fs]
dir_lst = [[], []]
for i in range(len(f_num)):
    dir_lst[i % 2].append(f_num[i])
x_lst = dir_lst[0]
y_lst = dir_lst[1]

can_x = False
can_y = False

dx = abs(sum(x_lst)) - abs(x)
if (dx % 2 == 1) or (dx < 0):
    pass
elif dx == 0:
    can_x = True
else:
    if part_sum0(x_lst, dx // 2):
        can_x = True

if can_x:
    dy = abs(sum(y_lst)) - abs(y)
    if (dy % 2 == 1) or (dy < 0):
        pass
    elif dy == 0:
        can_y = True
    else:
        if part_sum0(y_lst, dy // 2):
            can_y = True

if can_y:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s = input().strip()
goal = tuple(map(int, input().split()))

def change_dir(direc, case):
    if case == 0:
        direc += 1
        if direc == 5:
            direc = 1
    else:
        direc -= 1
        if direc == 0:
            direc = 4
    return direc

def go_in_dir(direc, pos):
    if direc == 1:
        return (pos[0]+1, pos[1])
    elif direc == 2:
        return (pos[0], pos[1]+1)
    elif direc == 3:
        return (pos[0]-1, pos[1])
    else:
        return (pos[0], pos[1]-1)

def exec_s(s, goal, direc=1, pos=(0, 0)):
    if len(s) == 0:
        if pos == goal:
            return True
        else:
            return False

    new_pos = pos
    while len(s) > 0 and s[0] == 'F':
        new_pos = go_in_dir(direc, new_pos)
        s = s[1:]

    if len(s) == 0:
        if new_pos == goal:
            return True
        else:
            return False

    new_dir = change_dir(direc, 0)
    reached = exec_s(s[1:], goal, new_dir, new_pos)
    if reached:
        return True
    else:
        new_dir = change_dir(direc, 1)
        return exec_s(s[1:], goal, new_dir, new_pos)

if exec_s(s, goal):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

cmd = list(input())
end = tuple(map(int, input().split()))

count = 0
while len(cmd) > 0:
    if cmd[0] == "F":
        count += 1
        cmd.pop(0)
    else:
        break

start = (0 + count, 0)

listX = []
listY = []
flag = False

if len(cmd) > 0:
    cmd.pop(0)
count = 0
for c in cmd:
    if c == "F":
        count += 1
    else:
        if flag:
            listX.append(count)
        else:
            listY.append(count)
        flag = not flag
        count = 0
if count > 0:
    if flag:
        listX.append(count)
    else:
        listY.append(count)


def turnX(x, i):
    if i == len(listX):
        if x == end[0]:
            return True
        else:
            return False
    step = listX[i]
    pos1 = x + step
    pos2 = x - step
    if turnX(pos1, i + 1):
        return True
    if turnX(pos2, i + 1):
        return True
    return False

def turnY(y, i):
    if i == len(listY):
        if y == end[1]:
            return True
        else:
            return False
    step = listY[i]
    pos1 = y + step
    pos2 = y - step
    if turnY(pos1, i + 1):
        return True
    if turnY(pos2, i + 1):
        return True
    return False

result = turnX(start[0], 0)

if result:
    result = turnY(start[1], 0)

print("Yes" if result else "No")

Submission status: Runtime Error

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

cmd = list(input())
end = tuple(map(int, input().split()))

count = 0
while len(cmd) > 0:
    if cmd[0] == "F":
        count += 1
        cmd.pop(0)
    else:
        break

start = (0 + count, 0)

list = []

if len(cmd) > 0:
    cmd.pop(0)
count = 0
for c in cmd:
    if c == "F":
        count += 1
    else:
        list.append(count)
        count = 0
if count > 0:
    list.append(count)

def turn(pos, i):
    if i == len(list):
        if pos == end:
            return True
        else:
            return False

    step = list[i]
    if i % 2 == 0:
        # y
        pos1 = (pos[0], pos[1] + step)
        pos2 = (pos[0], pos[1] - step)
    else:
        pos1 = (pos[0] + step, pos[1])
        pos2 = (pos[0] - step, pos[1])

    if turn(pos1, i + 1):
        return True
    if turn(pos2, i + 1):
        return True
    return False

result = turn(start, 0)


print("Yes" if result else "No")

Submission status: Runtime Error

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

#print(s)

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

#print(susumu)

syokiti = susumu.pop(0)

susumu_NS = [i for i in susumu[::2] if i != 0]
susumu_EW = [i for i in susumu[1::2] if i != 0]

x -= syokiti

# ＥＷの部分和でx? NSの部分和でy？

LL = sum(susumu_NS)+2
dp = [[0 for i in range(4*LL)] for j in range(1+len(susumu_NS))]
dp[0][2*LL] = 1


for j in range(len(susumu_NS)):
#    print('j='),
#    print(j)
    for i in range(LL,3*LL):
#        a=0
#        print(i+susumu_NS[j])
        dp[j+1][i] = dp[j][i+susumu_NS[j]] | dp[j][i-susumu_NS[j]]

can_y = 0
if dp[len(susumu_NS)][y+2*LL] != 0:
    can_y = 1
#print(susumu_NS)
#print(can_y)
    
#########################################
LL = sum(susumu_EW)+2
dp = [[0 for i in range(4*LL)] for j in range(1+len(susumu_EW))]
dp[0][2*LL] = 1

for j in range(len(susumu_EW)):
#    print('j='),
#    print(j)
    for i in range(LL,3*LL):
#        a=0
#        print(i+susumu_NS[j])
        dp[j+1][i] = dp[j][i+susumu_EW[j]] | dp[j][i-susumu_EW[j]]

can_x = 0
if dp[len(susumu_EW)][x+2*LL] != 0:
    can_x = 1

#print(can_x)

if can_x == 1 & can_y == 1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:

Beta
  paiza.IO
新規コード
一覧
ウェブ開発  
New!
日本語  サインアップ ログイン
Python3 Split Button!	
Enter a title here
Main.py 
Success  

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
s=input()
x,y = [int(i) for i in input().split()]
#print(s)
susumu = [0]
for i in range(len(s)):
    if s[i] == 'F':
        susumu[-1] += 1
    else:
        susumu.append(0)
#print(susumu)
syokiti = susumu.pop(0)
susumu_NS = [i for i in susumu[::2] if i != 0]
susumu_EW = [i for i in susumu[1::2] if i != 0]
x -= syokiti
  実行 (Ctrl-Enter) Split Button!             
出力
入力
コメント 0
(0.04 sec)
 
No

Submission status: Runtime Error

Solution code:
s=list(map(len,input().split("T")))
x,y=map(int,input().split())
def f(i,w):
    if i==0:
        return w==0
    if (i,w) not in m:
        m[(i,w)]=f(i-1,w-t[i-1]) or f(i-1,w+t[i-1])
    return m[(i,w)]
m={}
t=sorted(s[2::2])
a=f(len(t),x-s[0])
m={}
t=sorted(s[1::2])
print(["No","Yes"][a and f(len(t),y)])

Submission status: Runtime Error

Solution code:
s=list(map(len,input().split("T")))
x,y=map(int,input().split())
def f(t,i,w):
    if i==0:
        return w==0
    return f(t,i-1,w-t[i-1]) or f(t,i-1,w+t[i-1])
print(["No","Yes"][f(sorted(s[2::2]),len(s[2::2]),x-s[0]) and f(sorted(s[1::2]),len(s[1::2]),y)])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 19 16:31:02 2017

@author: kotania
"""

import sys

sys.setrecursionlimit(10000)
        
# 判定関数
def judge(target, nlist) :
        
    size = len(nlist)
    
    if size == 1 :
        if target == nlist[0] or target == - nlist[0]:
            return True
        else :
            return False
    else :
        return judge(target - nlist[0], nlist[1:size]) or judge(target + nlist[0], nlist[1:size])
        
        

s = input()
xy = input().split()

s_list = list(s)
x = int(xy[0])
y = int(xy[1])

x_list = []
y_list = []

s_byT = s.split("T")

even = True

for s in s_byT :
    if even:
        x_list.append(len(s))
        even = False
    else:
        y_list.append(len(s))
        even = True


if judge(x, x_list) and judge(y, y_list):
    print ("Yes")
else :
    print ("No")

Submission status: Runtime Error

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

def recurse(ex,ey,instructions,index=0,x=0,y=0,direction=0):
    if x == ex and y == ey and index >= len(instructions):
        return True
    elif index >= len(instructions):
        return False
    directionsx = [1,0,-1,0]
    directionsy = [0,1,0,-1]
    if instructions[index] == "F":
        return recurse(ex,ey,instructions,index+1,directionsx[direction]+x,directionsy[direction]+y,direction)
    elif instructions[index] == "T":
        return recurse(ex,ey,instructions,index+1,x,y,(direction+1)%4) or recurse(ex,ey,instructions,index+1,x,y,(direction-1)%4)

print("Yes" if recurse(x,y,instructions) else "No")

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 19 16:31:02 2017

@author: kotania
"""

import sys

sys.setrecursionlimit(10000)
        
# 判定関数
def judge(target, nlist) :
        
    size = len(nlist)
    
    if size == 1 :
        if target == nlist[0] or target == - nlist[0]:
            return True
        else :
            return False
    else :
        return judge(target - nlist[0], nlist[1:size]) or judge(target + nlist[0], nlist[1:size])
        
        

s = input()
xy = input().split()

s_list = list(s)
x = int(xy[0])
y = int(xy[1])

x_list = []
y_list = []

flag = True # True:x, False:y
counter = 0

for s in s_list:

    if flag == True: # x
        if s == "T":
            x_list.append(counter)
            counter = 0
            flag = False
        elif s == "F":
            counter += 1
        
    elif flag == False: # y
        if s == "T":
            y_list.append(counter)
            counter = 0
            flag = True
        elif s == "F":
            counter += 1

# s が Tで終わっていないとき
if counter > 0 :
    if flag == True: # x
        x_list.append(counter)
    elif flag == False: # y
        y_list.append(counter)
        
if judge(x, x_list) and judge(y, y_list):
    print ("Yes")
else :
    print ("No")

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 19 16:31:02 2017

@author: kotania
"""


        
# 判定関数
def judge(target, nlist) :
        
    size = len(nlist)
    
    if size == 1 :
        if target == nlist[0] or target == - nlist[0]:
            return True
        else :
            return False
    else :
        return judge(target - nlist[0], nlist[1:size]) or judge(target + nlist[0], nlist[1:size])
        
        

s = input()
xy = input().split()

s_list = list(s)
x = int(xy[0])
y = int(xy[1])

x_list = []
y_list = []

flag = True # True:x, False:y
counter = 0

for s in s_list:

    if flag == True: # x
        if s == "T":
            x_list.append(counter)
            counter = 0
            flag = False
        elif s == "F":
            counter += 1
        
    elif flag == False: # y
        if s == "T":
            y_list.append(counter)
            counter = 0
            flag = True
        elif s == "F":
            counter += 1

# s が Tで終わっていないとき
if counter > 0 :
    if flag == True: # x
        x_list.append(counter)
    elif flag == False: # y
        y_list.append(counter)
        
if judge(x, x_list) and judge(y, y_list):
    print ("Yes")
else :
    print ("No")

Submission status: Runtime Error

Solution code:
def main():
    position = [0,0]
    count = 0
    global list
    list = []
    if (S.count('F')-abs(x)-abs(y)) < 0:
        print("No")
        exit()
    findPath(count,position,[1,0])
    if [x,y] in list:
        print("Yes")
    else:
        print("No")


def findPath(index,position,dic_vector):
    if len(S) == index:
        list.append(position.copy())
        # if [x,y] == position:
        #     print("Yes")
        #     exit()
        # else:
        return
    if S[index] == 'F':
        position = [position[0]+dic_vector[0],position[1]+dic_vector[1]]
        index+=1
        findPath(index,position.copy(),dic_vector)
    else:
        index+=1
        if dic_vector[0] !=0:
            findPath(index,position.copy(),[0,1])
            findPath(index,position.copy(),[0,-1])
        else:
            findPath(index,position.copy(),[1,0])
            findPath(index,position.copy(),[-1,0])


if __name__=="__main__":
    S = list(input())
    x,y = map(int,input().split())
    main()

Submission status: Runtime Error

Solution code:
def main():
    position = [0,0]
    count = 0
    if (S.count('F')-abs(x)-abs(y)) < 0:
        print("No")
        exit()
    findPath(count,position,[1,0])
    print("No")


def findPath(index,position,dic_vector):
    if len(S) == index:
        if [x,y] == position:
            print("Yes")
            exit()
        else:
            return
    if S[index] == 'F':
        position = [position[0]+dic_vector[0],position[1]+dic_vector[1]]
        index+=1
        findPath(index,position,dic_vector)
    else:
        index+=1
        if dic_vector[0] !=0:
            findPath(index,position,[0,1])
            findPath(index,position,[0,-1])
        else:
            findPath(index,position,[1,0])
            findPath(index,position,[-1,0])


if __name__=="__main__":
    S = list(input())
    x,y = map(int,input().split())
    main()

Submission status: Runtime Error

Solution code:
def main():
    position = [0,0]
    count = 0
    x_path = abs(target[0])
    y_path = abs(target[1])
    if (S.count('F')-x_path-y_path) < 0:
        print("No")
        exit()
    findPath(count,position,[1,0])
    print("No")


def findPath(index,position,dic_vector):
    if len(S) == index:
        if target == position:
            print("Yes")
            exit()
        else:
            return
    if S[index] == 'F':
        position = [position[0]+dic_vector[0],position[1]+dic_vector[1]]
        index+=1
        findPath(index,position,dic_vector)
    else:
        index+=1
        if dic_vector[0] !=0:
            findPath(index,position,[0,1])
            findPath(index,position,[0,-1])
        else:
            findPath(index,position,[1,0])
            findPath(index,position,[-1,0])


if __name__=="__main__":
    S = list(input())
    target = list(map(int,input().split(" ")))
    main()

Submission status: Runtime Error

Solution code:
import sys

def main():
    position = [0,0]
    count = 0
    findPath(count,position,[1,0])
    print("No")


def findPath(index,position,dic_vector):
    if len(S) == index:
        if target == position:
            print("Yes")
            sys.exit()
        return
    if S[index] == 'F':
        position = [position[0]+dic_vector[0],position[1]+dic_vector[1]]
        index+=1
        findPath(index,position,dic_vector)
    else:
        index+=1
        if dic_vector[0] !=0:
            findPath(index,position,[0,1])
            findPath(index,position,[0,-1])
        else:
            findPath(index,position,[1,0])
            findPath(index,position,[-1,0])


if __name__=="__main__":
    S = list(input())
    target = list(map(int,input().split(" ")))
    main()

Submission status: Runtime Error

Solution code:
def main():
    position = [0,0]
    count = 0
    findPath(count,position,[1,0])
    print("No")


def findPath(index,position,dic_vector):
    if len(S) == index:
        if target == position:
            print("Yes")
            exit()
        return 
    if S[index] == 'F':
            position = [position[0]+dic_vector[0],position[1]+dic_vector[1]]
            index+=1
            findPath(index,position,dic_vector)
    else:
            index+=1
            if dic_vector[0] !=0:
                findPath(index,position,[0,1])
                findPath(index,position,[0,-1])
            else:
                findPath(index,position,[1,0])
                findPath(index,position,[-1,0])


if __name__=="__main__":
    S = list(input())
    target = list(map(int,input().split(" ")))
    main()

Submission status: Runtime Error

Solution code:
def main():
    position = [0,0]
    count = 0
    findPath(count,position,[1,0])
    if flag:
        print("Yes")
    else:
        print("No")


def findPath(index,position,dic_vector):
    if len(S) == index:
        if target == position:
            global flag
            flag = True
        return
    if S[index] == 'F':
            position = [position[0]+dic_vector[0],position[1]+dic_vector[1]]
            index+=1
            findPath(index,position,dic_vector)
    else:
            index+=1
            if dic_vector[0] !=0:
                findPath(index,position,[0,1])
                findPath(index,position,[0,-1])
            else:
                findPath(index,position,[1,0])
                findPath(index,position,[-1,0])

if __name__=="__main__":
    S = list(input())
    target = list(map(int,input().split(" ")))
    flag = False
    main()

Submission status: Runtime Error

Solution code:
flag = False
def main():
    position = [0,0]
    count = 0
    findPath(count,position,[1,0])
    print("No")


def findPath(index,position,dic_vector):
    if len(S) == index:
        if target == position:
            print("Yes")
            exit()
        return 
    if S[index] == 'F':
            position = [position[0]+dic_vector[0],position[1]+dic_vector[1]]
            index+=1
            findPath(index,position,dic_vector)
    else:
            index+=1
            if dic_vector[0] !=0:
                findPath(index,position,[0,1])
                findPath(index,position,[0,-1])
            else:
                findPath(index,position,[1,0])
                findPath(index,position,[-1,0])

if __name__=="__main__":
    S = list(input())
    target = list(map(int,input().split(" ")))
    main()

Submission status: Runtime Error

Solution code:
def main():
    position = [0,0]
    x_path = abs(target[0])
    y_path = abs(target[1])
    if (S.count('F')-x_path-y_path) < 0:
        print("No")
        quit()
    count = 0
    findPath(count,position,[1,0])
    print("No")


def findPath(index,position,dic_vector):
    if len(S) == index:
        if target == position:
            print("Yes")
            quit()
        else:
            return
    if S[index] == 'F':
            position = [position[0]+dic_vector[0],position[1]+dic_vector[1]]
            index+=1
            findPath(index,position,dic_vector)
    else:
            index+=1
            if dic_vector[0] !=0:
                findPath(index,position,[0,1])
                findPath(index,position,[0,-1])
            else:
                findPath(index,position,[1,0])
                findPath(index,position,[-1,0])

if __name__=="__main__":
    S = list(input())
    target = list(map(int,input().split(" ")))
    main()

Submission status: Runtime Error

Solution code:
def move(key,gx,gy,x,y,mx,my):
    if key[0]=='F':
        return move(key[1::],gx,gy,x+mx,y+my,mx,my)
    elif key[0]=='T':
        if mx==0:
            return move(key[1::],gx,gy,x,y,1,0)
            return move(key[1::],gx,gy,x,y,-1,0)
        else:
            return move(key[1::],gx,gy,x,y,0,1)
            return move(key[1::],gx,gy,x,y,0,-1)
    else:
        if x==gx and y==gy:
            return 1
        else:
            return 0

s1=input()
s2=input().split(' ')
ans=0
ans+=move(s1+'X',int(s2[0]),int(s2[1]),0,0,1,0)
if ans==0:
    print('No\n')
else:
    print('Yes\n')

Submission status: Runtime Error

Solution code:
def main():
    position = [0,0]
    x_path = abs(target[0])
    y_path = abs(target[1])
    if (S.count('F')-x_path-y_path) < 0:
        print("No")
        exit()
    count = 0
    findPath(count,position,[1,0])
    print("No")


def findPath(index,position,dic_vector):
    if len(S) == index:
        if target == position:
            print("Yes")
            exit()
        else:
            return
    try:
        if S[index] == 'F':
            position = [position[0]+dic_vector[0],position[1]+dic_vector[1]]
            index+=1
            findPath(index,position,dic_vector)
        else:
            index+=1
            if dic_vector[0]:
                findPath(index,position,[0,1])
                findPath(index,position,[0,-1])
            else:
                findPath(index,position,[1,0])
                findPath(index,position,[-1,0])
    except Exception:
        print("No")

if __name__=="__main__":
    S = list(input())
    target = list(map(int,input().split(" ")))
    main()

Submission status: Runtime Error

Solution code:
def main():
    position = [0,0]
    x_path = abs(target[0])
    y_path = abs(target[1])
    if (S.count('F')-x_path-y_path)<0:
        print("No")
        exit()
    count = 0
    try:
        findPath(count,position,[1,0])
    except Exception:
        raise Exception
    print("No")


def findPath(index,position,dic_vector):
    if len(S) == index:
        if target == position:
            print("Yes")
            exit()
        else:
            return
    if S[index] == 'F':
        position = [position[0]+dic_vector[0],position[1]+dic_vector[1]]
        index+=1
        findPath(index,position,dic_vector)
    else:
        index+=1
        if dic_vector[0]:
            findPath(index,position,[0,1])
            findPath(index,position,[0,-1])
        else:
            findPath(index,position,[1,0])
            findPath(index,position,[-1,0])


if __name__=="__main__":
    S = list(input())
    target = list(map(int,input().split(" ")))
    main()

Submission status: Runtime Error

Solution code:
def main():
    position = [0,0]
    x_path = abs(target[0])
    y_path = abs(target[1])
    if (S.count('F')-x_path-y_path)<0:
        print("No")
        exit()
    count = 0
    findPath(count,position,[1,0])
    print("No")


def findPath(index,position,dic_vector):
    if len(S) == index:
        if target == position:
            print("Yes")
            exit()
        else:
            return False
    if S[index] == 'F':
        position = [position[0]+dic_vector[0],position[1]+dic_vector[1]]
        index+=1
        findPath(index,position,dic_vector)
    else:
        index+=1
        if dic_vector[0]:
            findPath(index,position,[0,1])
            findPath(index,position,[0,-1])
        else:
            findPath(index,position,[1,0])
            findPath(index,position,[-1,0])


if __name__=="__main__":
    S = list(input())
    target = list(map(int,input().split(" ")))
    main()

Submission status: Runtime Error

Solution code:
def main():
    dic_vector = [1,0]
    position = [0,0]
    x_path = abs(target[0])
    y_path = abs(target[1])
    if (S.count('F')-x_path-y_path)<0:
        print("No")
        exit()
    count = 0
    findPath(count,position,dic_vector)
    print("No")


def findPath(index,position,dic_vector):
    if len(S) == index:
        if target == position:
            print("Yes")
            exit()
        else:
            return
    if S[index] == 'F':
        position = [position[0]+dic_vector[0],position[1]+dic_vector[1]]
        index+=1
        findPath(index,position,dic_vector)
    else:
        index+=1
        if dic_vector[0]:
            dic_vector = [0,1]
            findPath(index,position,dic_vector)
            dic_vector = [0,-1]
            findPath(index,position,dic_vector)
        else:
            dic_vector = [1,0]
            findPath(index,position,dic_vector)
            dic_vector = [-1,0]
            findPath(index,position,dic_vector)


if __name__=="__main__":
    S = list(input())
    target = list(map(int,input().split(" ")))
    main()