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 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()
        return
    if S[index] == 'F':
        position = [position[0]+dic_vector[0],position[1]+dic_vector[1]]
        findPath(index+1,position,dic_vector)
    else:
        if dic_vector[0]:
            dic_vector = [0,1]
            findPath(index+1,position,dic_vector)
            dic_vector = [0,-1]
            findPath(index+1,position,dic_vector)
        else:
            dic_vector = [1,0]
            findPath(index+1,position,dic_vector)
            dic_vector = [-1,0]
            findPath(index+1,position,dic_vector)


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,S,position,dic_vector)
    print("No")


def findPath(index,S,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]]
        findPath(index+1,S,position,dic_vector)
    else:
        if dic_vector[0]:
            dic_vector = [0,1]
            findPath(index+1,S,position,dic_vector)
            dic_vector = [0,-1]
            findPath(index+1,S,position,dic_vector)
        else:
            dic_vector = [1,0]
            findPath(index+1,S,position,dic_vector)
            dic_vector = [-1,0]
            findPath(index+1,S,position,dic_vector)


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

Submission status: Runtime Error

Solution code:
s=input()
x,y=[int(i) for i in input().split()]
count=0
x_v=[]
y_v=[]
 
dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            if count!=0:
                x_v.append(count)
            dir=0
            count=0
 
        else:
            if count!=0:
                y_v.append(count)
            dir=1
            count=0
 
    if i==len(s)-1:
        if dir==1 and count!=0:
            x_v.append(count)
        elif dir==0 and count!=0:
            y_v.append(count)
 
number_x=sum(x_v)+x_v[0]
x_check=0
dp_x=[[0 for i in range(number_x+1)] for j in range(len(x_v))]
if sum(x_v)!=0:
    dp_x[0][0]=1
 
for i in range(len(x_v)-1):
    for j in range(number_x+1):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][abs(j-x_v[i+1])]=1,1
 
if sum(x_v)!=0 and sum(x_v)>=abs(x) and x>=0:
  if dp_x[len(x_v)-1][abs(x-x_v[0])]==1:
    x_check=1
    
elif sum(x_v)!=0 and sum(x_v)>=abs(x) and x<0:
  if dp_x[len(x_v)-1][abs(x)+x_v[0]]==1:
    x_check=1
 
elif sum(x_v)==0:
  if x==0:
    x_check=1  
 
 
number_y=sum(y_v)
y_check=0
dp_y=[[0 for i in range(number_y+1)] for j in range(len(y_v))]
if sum(y_v)!=0:
    dp_y[0][y_v[0]]=1 
 
if sum(y_v)!=0 and x_check==1:
  for i in range(len(y_v)-1):
    for j in range(number_y+1):
          if dp_y[i][j]==1:
              dp_y[i+1][j+y_v[i+1]], dp_y[i+1][abs(j-y_v[i+1])]=1,1
 
if sum(y_v)!=0 and sum(y_v)>=abs(y):
  if dp_y[len(y_v)-1][abs(y)]==1:
    y_check=1
elif sum(y_v)==0:
  if y==0:
    y_check=1
 
if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s=input()
x,y=[int(i) for i in input().split()]
count=0
x_v=[]
y_v=[]
 
dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            if count!=0:
                x_v.append(count)
            dir=0
            count=0
 
        else:
            if count!=0:
                y_v.append(count)
            dir=1
            count=0
 
    if i==len(s)-1:
        if dir==1 and count!=0:
            x_v.append(count)
        elif dir==0 and count!=0:
            y_v.append(count)
 
number_x=sum(x_v)
x_check=0
dp_x=[[0 for i in range(number_x+1)] for j in range(len(x_v))]
if sum(x_v)!=0:
    dp_x[0][0]=1
 
for i in range(len(x_v)-1):
    for j in range(number_x+1):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][abs(j-x_v[i+1])]=1,1
 
if sum(x_v)!=0 and sum(x_v)>=abs(x) and x>=0:
  if dp_x[len(x_v)-1][abs(x-x_v[0])]==1:
    x_check=1
    
elif sum(x_v)!=0 and sum(x_v)>=abs(x) and x<0:
  if dp_x[len(x_v)-1][abs(x)+x_v[0]]==1:
    x_check=1
 
elif sum(x_v)==0:
  if x==0:
    x_check=1  
 
 
number_y=sum(y_v)
y_check=0
dp_y=[[0 for i in range(number_y+1)] for j in range(len(y_v))]
if sum(y_v)!=0:
    dp_y[0][y_v[0]]=1 
 
if sum(y_v)!=0 and x_check==1:
  for i in range(len(y_v)-1):
    for j in range(number_y+1):
          if dp_y[i][j]==1:
              dp_y[i+1][j+y_v[i+1]], dp_y[i+1][abs(j-y_v[i+1])]=1,1
 
if sum(y_v)!=0 and sum(y_v)>=abs(y):
  if dp_y[len(y_v)-1][abs(y)]==1:
    y_check=1
elif sum(y_v)==0:
  if y==0:
    y_check=1
 
if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
number_x=sum(x_v)
x_check=0
dp_x=[[0 for i in range(number_x+1)] for j in range(len(x_v))]
if sum(x_v)!=0:
    dp_x[0][0]=1

for i in range(len(x_v)-1):
    for j in range(number_x+1):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][abs(j-x_v[i+1])]=1,1
 


if sum(x_v)!=0 and sum(x_v)>=abs(x) and x>=0:
  if dp_x[len(x_v)-1][abs(x-x_v[0])]==1:
    x_check=1
elif sum(x_v)!=0 and sum(x_v)>=abs(x) and x<0:
  if dp_x[len(x_v)-1][abs(x+x_v[0])]==1:
    x_check=1


elif sum(x_v)==0:
  if x==0:
    x_check=1  
 
 
 
number_y=sum(y_v)
y_check=0
dp_y=[[0 for i in range(number_y+1)] for j in range(len(y_v))]
if sum(y_v)!=0:
    dp_y[0][y_v[0]]=1 
 
if sum(y_v)!=0 and x_check==1:
  for i in range(len(y_v)-1):
    for j in range(number_y+1):
          if dp_y[i][j]==1:
              dp_y[i+1][j+y_v[i+1]], dp_y[i+1][abs(j-y_v[i+1])]=1,1
 
if sum(y_v)!=0 and sum(y_v)>=abs(y):
  if dp_y[len(y_v)-1][abs(y)]==1:
    y_check=1
elif sum(y_v)==0:
  if y==0:
    y_check=1

Submission status: Runtime Error

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

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            if count!=0:
                x_v.append(count)
            dir=0
            count=0

        else:
            if count!=0:
                y_v.append(count)
            dir=1
            count=0

    if i==len(s)-1:
        if dir==1 and count!=0:
            x_v.append(count)
        elif dir==0 and count!=0:
            y_v.append(count)

number_x=sum(x_v)
x_check=0
dp_x=[[0 for i in range(number_x+1)] for j in range(len(x_v))]
if sum(x_v)!=0:
    dp_x[0][0]=1

for i in range(len(x_v)-1):
    for j in range(number_x+1):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][abs(j-x_v[i+1])]=1,1
 


if sum(x_v)!=0 and sum(x_v)>=abs(x):
  if dp_x[len(x_v)-1][abs(x-x_v[0])]==1:
    x_check=1

 
elif sum(x_v)==0:
  if x==0:
    x_check=1  
 
 
 
number_y=sum(y_v)
y_check=0
dp_y=[[0 for i in range(number_y+1)] for j in range(len(y_v))]
if sum(y_v)!=0:
    dp_y[0][y_v[0]]=1 
 
if sum(y_v)!=0 and x_check==1:
  for i in range(len(y_v)-1):
    for j in range(number_y+1):
          if dp_y[i][j]==1:
              dp_y[i+1][j+y_v[i+1]], dp_y[i+1][abs(j-y_v[i+1])]=1,1
 
if sum(y_v)!=0 and sum(y_v)>=abs(y):
  if dp_y[len(y_v)-1][abs(y)]==1:
    y_check=1
elif sum(y_v)==0:
  if y==0:
    y_check=1

if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            if count!=0:
                x_v.append(count)
            dir=0
            count=0

        else:
            if count!=0:
                y_v.append(count)
            dir=1
            count=0

    if i==len(s)-1:
        if dir==1 and count!=0:
            x_v.append(count)
        elif dir==0 and count!=0:
            y_v.append(count)

number_x=sum(x_v)
x_check=0
dp_x=[[0 for i in range(number_x+1)] for j in range(len(x_v))]
if sum(x_v)!=0:
    dp_x[0][x_v[0]-x_v[0]]=1

for i in range(len(x_v)-1):
    for j in range(number_x+1):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]-x_v[0]], dp_x[i+1][abs(j-x_v[i+1]-x_v[0])]=1,1

if sum(x_v)!=0 and sum(x_v)>=abs(x-x_v[0]):
  if dp_x[len(x_v)-1][abs(x-x_v[0])]==1:
    x_check=1


elif sum(x_v)==0:
  if x==0:
    x_check=1  



number_y=sum(y_v)
y_check=0
dp_y=[[0 for i in range(number_y+1)] for j in range(len(y_v))]
if sum(y_v)!=0:
    dp_y[0][y_v[0]]=1

if sum(y_v)!=0 and x_check==1:
  for i in range(len(y_v)-1):
    for j in range(number_y+1):
          if dp_y[i][j]==1:
              dp_y[i+1][j+y_v[i+1]], dp_y[i+1][abs(j-y_v[i+1])]=1,1

if sum(y_v)!=0 and sum(y_v)>=abs(y):
  if dp_y[len(y_v)-1][abs(y)]==1:
    y_check=1
elif sum(y_v)==0:
  if y==0:
    y_check=1

if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
order = input()
pos = input()
x = pos.split()[0]
y = pos.split()[1]
dir = 0  # yoko
count = [[], []]
tmp = 0
for com in order:
    if com == "F":
        tmp += 1
    else:
        if tmp != 0:
            count[dir].append(tmp)
        dir = abs(dir - 1)
        tmp = 0
if tmp != 0:
    count[dir].append(tmp)
first = count[0][0]
count[0].pop(0)


def Check(pos, numlist):
    tuple = set([0])
    for num in numlist:
        for p in list(tuple):
            tuple.add(p+num)
            tuple.add(p-num)
    return True if pos in tuple else False


print("Yes" if Check(int(x) - first, count[0]) and Check(int(y), count[1]) else "No")

Submission status: Runtime Error

Solution code:
order = input()
pos = input()
x = pos.split()[0]
y = pos.split()[1]
dir = 0  # yoko
count = [[], []]
tmp = 0
for com in order:
    if com == "F":
        tmp += 1
    else:
        if tmp != 0:
            count[dir].append(tmp)
        dir = abs(dir - 1)
        tmp = 0
if tmp != 0:
    count[dir].append(tmp)
print(count)
first = count[0][0]
count[0].pop(0)


def Check(pos, numlist):
    tuple = set([0])
    for num in numlist:
        for p in list(tuple):
            tuple.add(p+num)
            tuple.add(p-num)
    return True if pos in tuple else False


print("Yes" if Check(int(pos.split()[0]) - first, count[0]) and Check(int(pos.split()[1]), count[1]) else "No")

Submission status: Runtime Error

Solution code:
# coding:utf-8                                                                  

alls = raw_input()
tarx, tary = map(int, raw_input().split())

ss = alls.split("T")

xs = []
ys = []
posx = set()
posy = set()
posy.add(0)
for i, s in enumerate(ss):
    if i == 0:
        posx.add(len(s))
    elif i % 2 == 0:
        xs.add(len(s))
    else:
        ys.add(len(s))

for x in xs:
    tmpx = set()
    for px in posx:
        tmpx.add(px+x)
        tmpx.add(px-x)
    posx = tmpx

for y in ys:
    tmpy = set()
    for py in posy:
        tmpy.add(py+y)
        tmpy.add(py-y)
    posy = tmpy

if tarx in posx and tary in posy:
    print "Yes"
else:
    print "No"

Submission status: Runtime Error

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

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        





number_x=sum(x_v)
x_check=0
dp_x=[[0 for i in range(number_x+1)] for j in range(len(x_v))]
dp_x[0][x_v[0]]=1
number_y=sum(y_v)
y_check=0
dp_y=[[0 for i in range(number_y+1)] for j in range(len(y_v))]
dp_y[0][y_v[0]]=1



for i in range(len(x_v)-1):
#    for j in range(min(int(number_x/2+2+abs(x)),number_x+1)):
    for j in range(number_x+1):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][abs(j-x_v[i+1])]=1,1

if sum(x_v)!=0 and sum(x_v)>=abs(x):
  if dp_x[len(x_v)-1][abs(x)]==1:
    x_check=1
elif sum(x_v)==0:
  if x==0:
    x_check=1  

if sum(y_v)!=0 and x_check==1:


  for i in range(len(y_v)-1):
#      for j in range(min(int(number_y/2+2+abs(y)),number_y+1)):
    for j in range(number_y+1):
          if dp_y[i][j]==1:
              dp_y[i+1][j+y_v[i+1]], dp_y[i+1][abs(j-y_v[i+1])]=1,1

if sum(y_v)!=0 and sum(y_v)>=abs(y):
  if dp_y[len(y_v)-1][abs(y)]==1:
    y_check=1
elif sum(y_v)==0:
  if y==0:
    y_check=1

if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        





number_x=sum(x_v)
x_check=0
dp_x=[[0 for i in range(number_x+1)] for j in range(len(x_v))]
dp_x[0][x_v[0]]=1

for i in range(len(x_v)-1):
#    for j in range(min(int(number_x/2+2+abs(x)),number_x+1)):
    for j in range(number_x+1):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][abs(j-x_v[i+1])]=1,1

if sum(x_v)!=0 and sum(x_v)>=abs(x):
  if dp_x[len(x_v)-1][abs(x)]==1:
    x_check=1
elif sum(x_v)==0:
  if x==0:
    x_check=1  

if sum(y_v)!=0 and x_check==1:
  number_y=sum(y_v)
  y_check=0
  dp_y=[[0 for i in range(number_y+1)] for j in range(len(y_v))]
  dp_y[0][y_v[0]]=1

  for i in range(len(y_v)-1):
#      for j in range(min(int(number_y/2+2+abs(y)),number_y+1)):
    for j in range(number_y+1):
          if dp_y[i][j]==1:
              dp_y[i+1][j+y_v[i+1]], dp_y[i+1][abs(j-y_v[i+1])]=1,1

if sum(y_v)!=0 and sum(y_v)>=abs(y):
  if dp_y[len(y_v)-1][abs(y)]==1:
    y_check=1
elif sum(y_v)==0:
  if y==0:
    y_check=1

if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        





number_x=sum(x_v)
x_check=0
dp_x=[[0 for i in range(number_x+1)] for j in range(len(x_v))]
dp_x[0][x_v[0]]=1

for i in range(len(x_v)-1):
    for j in range(min(int(number_x/2+2+abs(x)),number_x+1)):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][abs(j-x_v[i+1])]=1,1

if sum(x_v)!=0 and sum(x_v)>=abs(x):
  if dp_x[len(x_v)-1][abs(x)]==1:
    x_check=1
elif sum(x_v)==0:
  if x==0:
    x_check=1  

if sum(y_v)!=0 and x_check==1:
  number_y=sum(y_v)
  y_check=0
  dp_y=[[0 for i in range(number_y+1)] for j in range(len(y_v))]
  dp_y[0][y_v[0]]=1

  for i in range(len(y_v)-1):
      for j in range(min(int(number_y/2+2+abs(y)),number_y+1)):
          if dp_y[i][j]==1:
              dp_y[i+1][j+y_v[i+1]], dp_y[i+1][abs(j-y_v[i+1])]=1,1

if sum(y_v)!=0 and sum(y_v)>=abs(y):
  if dp_y[len(y_v)-1][abs(y)]==1:
    y_check=1
elif sum(y_v)==0:
  if y==0:
    y_check=1

if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        





number_x=sum(x_v)
x_check=0
dp_x=[[0 for i in range(number_x+1)] for j in range(len(x_v))]
dp_x[0][x_v[0]]=1

for i in range(len(x_v)-1):
    for j in range(min(int(number_x/2+2+abs(x)),number_x+1)):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][abs(j-x_v[i+1])]=1,1

if sum(x_v)!=0:
  if dp_x[len(x_v)-1][abs(x)]==1:
    x_check=1
else:
  if x==0:
    x_check=1  

if sum(y_v)!=0 and x_check==1:
  number_y=sum(y_v)
  y_check=0
  dp_y=[[0 for i in range(number_y+1)] for j in range(len(y_v))]
  dp_y[0][y_v[0]]=1

  for i in range(len(y_v)-1):
      for j in range(min(int(number_y/2+2+abs(y)),number_y+1)):
          if dp_y[i][j]==1:
              dp_y[i+1][j+y_v[i+1]], dp_y[i+1][abs(j-y_v[i+1])]=1,1

if sum(y_v)!=0:
  if dp_y[len(y_v)-1][abs(y)]==1:
    y_check=1
else:
  if y==0:
    y_check=1

if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        





number_x=sum(x_v)
x_check=0
dp_x=[[0 for i in range(number_x+1)] for j in range(len(x_v))]
dp_x[0][x_v[0]]=1

for i in range(len(x_v)-1):
    for j in range(min(int(number_x/2+2+abs(x)),number_x+1)):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][abs(j-x_v[i+1])]=1,1

if sum(x_v)!=0:
  if dp_x[len(x_v)-1][abs(x)]==1:
    x_check=1
else:
  if x==0:
    x_check=1  

if sum(y_v)!=0 and number_x==1:
  number_y=sum(y_v)
  y_check=0
  dp_y=[[0 for i in range(number_y+1)] for j in range(len(y_v))]
  dp_y[0][y_v[0]]=1

  for i in range(len(y_v)-1):
      for j in range(min(int(number_y/2+2+abs(y)),number_y+1)):
          if dp_y[i][j]==1:
              dp_y[i+1][j+y_v[i+1]], dp_y[i+1][abs(j-y_v[i+1])]=1,1

if sum(y_v)!=0:
  if dp_y[len(y_v)-1][abs(y)]==1:
    y_check=1
else:
  if y==0:
    y_check=1

if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        





number_x=sum(x_v)
x_check=0
dp_x=[[0 for i in range(number_x+1)] for j in range(len(x_v))]
dp_x[0][x_v[0]]=1

for i in range(len(x_v)-1):
    for j in range(min(int(number_x/2+2+abs(x)),number_x+1)):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][abs(j-x_v[i+1])]=1,1

if sum(x_v)!=0:
  if dp_x[len(x_v)-1][abs(x)]==1:
    x_check=1
else:
  if x==0:
    x_check=1  

if sum(y_v)!=0 and x_number==1:
  number_y=sum(y_v)
  y_check=0
  dp_y=[[0 for i in range(number_y+1)] for j in range(len(y_v))]
  dp_y[0][y_v[0]]=1

  for i in range(len(y_v)-1):
      for j in range(min(int(number_y/2+2+abs(y)),number_y+1)):
          if dp_y[i][j]==1:
              dp_y[i+1][j+y_v[i+1]], dp_y[i+1][abs(j-y_v[i+1])]=1,1

if sum(y_v)!=0:
  if dp_y[len(y_v)-1][abs(y)]==1:
    y_check=1
else:
  if y==0:
    y_check=1

if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        





number_x=sum(x_v)
x_check=0
dp_x=[[0 for i in range(number_x+1)] for j in range(len(x_v))]
dp_x[0][x_v[0]]=1

for i in range(len(x_v)-1):
    for j in range(min(int(number_x/2+2+abs(x)),number_x+1)):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][abs(j-x_v[i+1])]=1,1

if sum(x_v)!=0:
  if dp_x[len(x_v)-1][abs(x)]==1:
    x_check=1
else:
  if x==0:
    x_check=1  

if sum(y_v)!=0:
  number_y=sum(y_v)
  y_check=0
  dp_y=[[0 for i in range(number_y+1)] for j in range(len(y_v))]
  dp_y[0][y_v[0]]=1

  for i in range(len(y_v)-1):
      for j in range(min(int(number_y/2+2+abs(y)),number_y+1)):
          if dp_y[i][j]==1:
              dp_y[i+1][j+y_v[i+1]], dp_y[i+1][abs(j-y_v[i+1])]=1,1

if sum(y_v)!=0:
  if dp_y[len(y_v)-1][abs(y)]==1:
    y_check=1
else:
  if y==0:
    y_check=1

if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        

number_x=sum(x_v)
x_check=0
dp_x=[[0 for i in range(number_x+1)] for j in range(len(x_v))]
dp_x[0][x_v[0]]=1

for i in range(len(x_v)-1):
    for j in range(min(int(number_x/2+2),number_x+1)):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][abs(j-x_v[i+1])]=1,1

if sum(x_v)!=0:
  if dp_x[len(x_v)-1][abs(x)]==1:
    x_check=1
else:
  if x==0:
    x_check=1  

if sum(y_v)!=0:
  number_y=sum(y_v)
  y_check=0
  dp_y=[[0 for i in range(number_y+1)] for j in range(len(y_v))]
  dp_y[0][y_v[0]]=1

  for i in range(len(y_v)-1):
      for j in range(min(int(number_y/2+2),number_y+1)):
          if dp_y[i][j]==1:
              dp_y[i+1][j+y_v[i+1]], dp_y[i+1][abs(j-y_v[i+1])]=1,1

if sum(y_v)!=0:
  if dp_y[len(y_v)-1][abs(y)]==1:
    y_check=1
else:
  if y==0:
    y_check=1

if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        

number_x=sum(x_v)
x_check=0
dp_x=[[0 for i in range(number_x+1)] for j in range(len(x_v))]
dp_x[0][x_v[0]]=1

for i in range(len(x_v)-1):
    for j in range(min(int(number_x/2+2),number_x+1)):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][abs(j-x_v[i+1])]=1,1

if sum(x_v)!=0:
  if dp_x[len(x_v)-1][abs(x)]==1:
    x_check=1
else:
  if x==0:
    x_check=1  


number_y=sum(y_v)
y_check=0
dp_y=[[0 for i in range(number_y+1)] for j in range(len(y_v))]
dp_y[0][y_v[0]]=1

for i in range(len(y_v)-1):
    for j in range(min(int(number_y/2+2),number_y+1)):
        if dp_y[i][j]==1:
            dp_y[i+1][j+y_v[i+1]], dp_y[i+1][abs(j-y_v[i+1])]=1,1

if sum(y_v)!=0:
  if dp_y[len(y_v)-1][abs(y)]==1:
    y_check=1
  if y==0:
    y_check=1

if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        

x_check=0
dp_x=[[0 for i in range(2*sum(x_v)+20)] for j in range(len(x_v))]
dp_x[0][sum(x_v)+10+x_v[0]]=1

dp_z=[sum(x_v)+10+x_v[0]]
dp_z2=[]
for i in range(len(x_v)-1):
    for j in dp_z:
        dp_x[i+1][j+x_v[i+1]], dp_x[i+1][j-x_v[i+1]]=1,1
        if j+x_v[i+1] not in dp_z2:
            dp_z2.append(j+x_v[i+1])
        if j-x_v[i+1] not in dp_z2:            
            dp_z2.append(j-x_v[i+1])
    dp_z=dp_z2
    dp_z2=[]    
#    for j in range(2*sum(x_v)+20):
#        if dp_x[i][j]==1:
#            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][j-x_v[i+1]]=1,1

if dp_x[len(x_v)-1][sum(x_v)+10+x]==1:
    x_check=1

dp_z=[sum(y_v)+10+y_v[0]]
dp_z2=[]

y_check=0
dp_y=[[0 for i in range(2*sum(y_v)+20)] for j in range(len(y_v))]
dp_y[0][sum(y_v)+10+y_v[0]]=1
dp_y[0][sum(y_v)+10-y_v[0]]=1


for i in range(len(y_v)-1):
    for j in dp_z:
        dp_y[i+1][j+y_v[i+1]], dp_y[i+1][j-y_v[i+1]]=1,1
        if j+y_v[i+1] not in dp_z2:
            dp_z2.append(j+y_v[i+1])
        if j-x_v[i+1] not in dp_z2:            
            dp_z2.append(j-y_v[i+1])
    dp_z=dp_z2
    dp_z2=[]      
  
 
  
#    for j in range(2*sum(y_v)+20):
#        if dp_y[i][j]==1:
#            dp_y[i+1][j+y_v[i+1]], dp_y[i+1][j-y_v[i+1]]=1,1

if dp_y[len(y_v)-1][sum(y_v)+10+y]==1:
    y_check=1


if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")
#print(len(y_v))

Submission status: Runtime Error

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

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        

x_check=0
dp_x=[[0 for i in range(2*sum(x_v)+20)] for j in range(len(x_v)+1)]
dp_x[0][sum(x_v)+10+x_v[0]]=1

for i in range(len(x_v)-1):
    for j in range(2*sum(x_v)+20):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][j-x_v[i+1]]=1,1

if dp_x[len(x_v)-1][sum(x_v)+10+x]==1:
    x_check=1


y_check=0
dp_y=[[0 for i in range(2*sum(y_v)+20)] for j in range(len(y_v)+1)]
dp_y[0][sum(y_v)+10+y_v[0]]=1
dp_y[0][sum(y_v)+10-y_v[0]]=1

for i in range(len(y_v)-1):
    for j in range(2*sum(y_v)+20):
        if dp_y[i][j]==1:
            dp_y[i+1][j+y_v[i+1]], dp_y[i+1][j-y_v[i+1]]=1,1

if dp_y[len(y_v)-1][sum(y_v)+10+y]==1:
    y_check=1


if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        

x_check=0
dp_x=[[0 for i in range(4*sum(x_v)+2)] for j in range(len(x_v))]
dp_x[0][2*sum(x_v)+x_v[0]]=1

for i in range(len(x_v)-1):
    for j in range(4*sum(x_v)+2):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][j-x_v[i+1]]=1,1
if sum(x_v)>=abs(x):
    if dp_x[len(x_v)-1][2*sum(x_v)+x]==1:
        x_check=1


y_check=0
dp_y=[[0 for i in range(4*sum(y_v)+2)] for j in range(len(y_v))]
dp_y[0][2*sum(y_v)+y_v[0]]=1
dp_y[0][2*sum(y_v)-y_v[0]]=1

for i in range(len(y_v)-1):
    for j in range(2*sum(y_v)+2):
        if dp_y[i][j]==1:
            dp_y[i+1][j+y_v[i+1]], dp_y[i+1][j-y_v[i+1]]=1,1
if sum(y_v)>=abs(y):
    if dp_y[len(y_v)-1][2*sum(y_v)+y]==1:
        y_check=1


if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")