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: Wrong Answer

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)]==1:
    x_check=1
 
elif sum(x_v)==0:
  if x==0:
    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: Wrong Answer

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=2*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]+sum(x_v)]=1

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

if sum(x_v)!=0 and sum(x_v)>=abs(x):
  if dp_x[len(x_v)-1][x+sum(x_v)]==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: Wrong Answer

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=2*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]+sum(x_v)]=1

for i in range(len(x_v)-1):
    for j in range(number_x+1):
        if dp_x[i][j]==1 and j+x_v[i+1]<=number_x+1 and j-x_v[i+1]>=0 :
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][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][x+sum(x_v)]==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: Wrong Answer

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]]=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



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)]==1:
    x_check=1
  if x<0 and sum(x_v)-x_v[0]<abs(x):
    x_check=0

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(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: Wrong Answer

Solution code:
s=input()
x,y=[int(i) for i in input().split()]
 
if x==0:
    print("No")

Submission status: Wrong Answer

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

if y==0:
    print("No")

Submission status: Wrong Answer

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)

if sum(y_v)==0:
    print("No")

Submission status: Wrong Answer

Solution code:
print("No")

Submission status: Wrong Answer

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]]=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



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: Wrong Answer

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 and count!=0:
            x_v.append(count)
            dir=0
            count=0
        elif  dir==0 and 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]]=1

print(sum(y_v))
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



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: Wrong Answer

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))]
if sum(y_v)!=0:
    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: Wrong Answer

Solution code:
import sys
from collections import deque

s = deque(input() + 'T')
X, Y = map(int, input().split())

while True:
    if s[0] == 'T':
        break
    s.popleft()
    X -= 1

dirx = True
x_list = []
y_list = []
count = 0
for c in s:
    if c == 'F':
        count += 1
    else:
        if dirx:
            x_list.append(count)
        else:
            y_list.append(count)
        dirx = not(dirx)
        count = 0

if (sum(x_list) + X) % 2 != 0 or (sum(y_list) + Y) % 2 != 0:
    print('No')
    sys.exit()

dx = (sum(x_list) + abs(X)) // 2
dy = (sum(y_list) + abs(Y)) // 2

dp_x = [False for _ in range(dx + 1)]
dp_x[0] = True
for x in x_list:
    for i in range(dx + 1):
        if dp_x[i] and i + x <= dx:
            dp_x[i + x] = True
if not dp_x[dx]:
    print('No')
    sys.exit()

dp_y = [False for _ in range(dy + 1)]
dp_y[0] = True
for y in y_list:
    for i in range(dy + 1):
        if dp_y[i] and i + y <= dy:
            dp_y[i + y] = True
if not dp_y[dy]:
    print('No')
    sys.exit()

print('Yes')

Submission status: Wrong Answer

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

h,v = [],[]
hv = 0
for ft in s:
    if hv % 2 == 0:
        h.append(len(ft))
    else:
        v.append(len(ft))
    hv += 1
    
ax,ay = False,False
tx,ty = h.pop(0),0
sorted(h,reverse=True)
sorted(v,reverse=True)
for i in h:
    if tx > x:
        tx -= i
    else:
        tx += i
if tx == x:
    ax = True

for i in v:
    if ty > y:
        ty -= i
    else:
        ty += i
if ty == y:
    ay = True
    
if ax and ay:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

h,v = [],[]
hv = 0
for ft in s:
    if hv % 2 == 0:
        h.append(len(ft))
    else:
        v.append(len(ft))
    hv += 1
    
ax,ay = False,False
tx,ty = h.pop(0),0
sorted(h)
sorted(v)
for i in h:
    if tx > x:
        tx -= i
    else:
        tx += i
if tx == x:
    ax = True

for i in v:
    if ty > y:
        ty -= i
    else:
        ty += i
if ty == y:
    ay = True
    
if ax and ay:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

s = deque(input() + 'T')
X, Y = map(int, input().split())

while True:
    if s[0] == 'T':
        break
    s.popleft()
    X -= 1

dirx = True
x_list = []
y_list = []
count = 0
for c in s:
    if c == 'F':
        count += 1
    else:
        if dirx:
            x_list.append(count)
        else:
            y_list.append(count)
        dirx = not(dirx)
        count = 0

if (sum(x_list) + X) % 2 != 0 or (sum(y_list) + Y) % 2 != 0:
    print('No')
    sys.exit()

dx = abs((sum(x_list) + X) // 2)
dy = abs((sum(y_list) + Y) // 2)

dp_x = [False for _ in range(dx + 1)]
dp_x[0] = True
for x in x_list:
    for i in range(dx + 1):
        if dp_x[i] and i + x <= dx:
            dp_x[i + x] = True
if not dp_x[dx]:
    print('No')
    sys.exit()

dp_y = [False for _ in range(dy + 1)]
dp_y[0] = True
for y in y_list:
    for i in range(dy + 1):
        if dp_y[i] and i + y <= dy:
            dp_y[i + y] = True
if not dp_y[dy]:
    print('No')
    sys.exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
a = raw_input()
b = raw_input()

a = "".join( sorted( list(a) ) )
b = "".join( sorted( list(b) ) )

yes = True
printed = False

if len(a) < len(b):
    i = 0
    while i < len(a):
        if a[i] != b[i]:
            yes = False
            break
        i += 1
    if yes:
        print "Yes"
        printed = True

if not printed:
    i = 0
    b = "".join( sorted( list(b), reverse = True ) )

    while i < len(a):
        if a[i] < b[i]:
            print "Yes"
            printed = True
            break
        elif a[i] > b[i]:
            print "No"
            printed = True
            break
        i += 1
    if not printed:
        print "No"

if not printed:
    print "Yes"
    printed = True

Submission status: Wrong Answer

Solution code:
s=list(raw_input().split("T"))
x,y=map(int,raw_input().split())
cx,cy=len(s[0]),0
#print cx,cy
sx=s[2::2]
sy=s[1::2]
#print sx
#print sy
sx1=[len(_) for _ in sx]
sy1=[len(_) for _ in sy]
#print sx1
#print sy1

for i in sx1:
	if cx<x:
		cx+=i
	else:
		cx-=i

#print cx

for i in sy1:
	if cy<y:
		cy+=i
	else:
		cy-=i

#print cy
print "Yes" if cx==x and cy==y else "No"

Submission status: Wrong Answer

Solution code:
orientation =  (1,0)

directions = raw_input().strip().upper()
line = raw_input().split()

x = int(line[0])
y = int(line[1])

for c in directions:
    if c == "T":
        if orientation[1] == 0: #currently horizontal
            if y > 0:
                orientation = (0, 1)
            else:
                orientation = (0, -1)
        else:
            if x > 0:
                orientation = (1, 0)
            else:
                orientation = (-1, 0)
    else: # we moving
        if orientation[1] == 0: #horizontal
            x -= orientation[0]
        else:
            y -= orientation[1]

if x == 0 and y == 0:
    print "Yes"
else:
    print "No"

Submission status: Wrong Answer

Solution code:
my_x = 0
my_y = 0

orientation =  (1,0) # 0 = horizontal, 1 is vertical

directions = raw_input()
line = raw_input().split()

x = int(line[0])
y = int(line[1])


for c in directions:
    if c == "T":
        if orientation[1] == 0: #currently horizontal
            if y > 0:
                orientation = (0, 1)
            else:
                orientation = (0, -1)
        else:
            if x > 0:
                orientation = (1, 0)
            else:
                orientation = (-1, 0)
    else: # we moving
        if orientation[1] == 0: #horizontal
            x -= orientation[0]
        else:
            y -= orientation[1]

if x == 0 and y == 0:
    print "Yes"
else:
    print "No"

Submission status: Wrong Answer

Solution code:
my_x = 0
my_y = 0

orientation = 0 # 0 = horizontal, 1 is vertical

directions = raw_input()
line = raw_input().split()

x = int(line[0])
y = int(line[1])


for c in directions:
    if c == "F":
        if orientation == 0:
            my_x += 1
        else:
            my_y += 1
    else:
        orientation = 1 if orientation == 0 else 0

print my_x, my_y
if abs(my_x) >= abs(x) and abs(my_y) >= abs(y):
    if (abs(my_x) - abs(x)) % 2 == 0 and (abs(my_y) - abs(y)) % 2 == 0:
        print "Yes"
    else:
        print "No"
else:
    print "No"

Submission status: Wrong Answer

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

h,v = [],[]
hv = 0
temp = 0
s += "T"
for ft in s:
    if ft == "T":
        if hv % 2 == 0:
            h.append(temp)
        else:
            v.append(temp)
        hv += 1
        temp = 0
        continue
    temp += 1

dpx, dpy = [False for z in range(20000)],[False for z in range(20000)] #8000 bias
dpx[h[0] + 8000] = True
dpy[8000] = True
ax,ay = False,False
for i in range(1,len(h)):
    if i != len(h) - 1:
        for j in range(16001):
            if dpx[j]:
                dpx[j-h[i]] = True
                dpx[j+h[i]] = True
    else:
        for j in range(16001):
            if dpx[j]:
                if j-h[i]-8000 == x or j+h[i]-8000 == x:
                   ax = True

for i in range(len(v)):
    if i != len(v) - 1:
        for j in range(16001):
            if dpy[j]:
                dpy[j-v[i]] = True
                dpy[j+v[i]] = True
    else:
        for j in range(16001):
            if dpy[j]:
                if j-v[i]-8000 == y or j+v[i]-8000 == y:
                    ay = True

if ax and ay:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
a, b = 0, 0
x, y = map(int, input().split())
dx, dy = 1, 0
for tf in s:
    if tf == 'T':
        if dy == 0:
            if y > b: dy = 1
            else: dy = -1
            dx = 0
        elif dx == 0:
            if x > a: dx = 1
            else: dx = -1
            dy = 0
    else:
        a += dx * 1
        b += dy * 1
if a == x and y == b: print('Yes')
else: print('No')

Submission status: Wrong Answer

Solution code:
s=input().split('T')
p=list(map(int,input().split()))
mv=[len(i) for i in s]
d=[[],[]]
for i in range(len(mv)):
    d[i&1].append(mv[i])
x=d[0].copy()
y=d[1].copy()
t=[x.pop(),0]
x.sort()
y.sort()
while x!=[]:
    if t[0]>p[0]:t[0]-=x.pop()
    else:t[0]+=x.pop()
while y!=[]:
    if t[1] > p[1]:t[1] -= y.pop()
    else:t[1] += y.pop()
print(['No','Yes'][p==t])

Submission status: Wrong Answer

Solution code:
s, (x, y) = raw_input().split('T'), map(int, raw_input().split())
cx, cy = len(s[0]), 0
for _ in [len(_) for _ in s[2::2]]:
    cx += _ if cx < x else -_
for _ in [len(_) for _ in s[1::2]]:
    cy += _ if cy < y else -_
print 'Yes' if (cx, cy) == (x, y) else 'No'

Submission status: Wrong Answer

Solution code:
s=input().split('T')
p=list(map(int,input().split()))
mv=[len(i) for i in s]
d=[[],[]]
for i in range(len(mv)):
    d[i&1].append(mv[i])
x=d[0].copy()
y=d[1].copy()
t=[x[0],0]
x.sort()
y.sort()
while x!=[]:
    if t[0]>p[0]:t[0]-=x.pop()
    else:t[0]+=x.pop()
while y!=[]:
    if t[1] > p[1]:
        t[1] -= y.pop()
    else:t[1] += y.pop()
print(['No','Yes'][p==t])

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import math

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

mx = []
my = []

cnt = 0
direction = 0
for c in s:
    if c == "F":
        cnt += 1
    elif direction == 0:
        mx.append(cnt)
        cnt = 0
        direction = 1
    else:
        my.append(cnt)
        cnt = 0
        direction = 0

mx.append(cnt) if direction == 0 else my.append(cnt)

dpx = {}
xs = mx.pop(0)
dpx[xs] = True
ys = 0
dpy = {}
dpy[0] = True
for i in range(8000):
    for dx in mx:
        if x + dx in dpx or x - dx in dpx:
            dpx[x] = True

for i in range(8000):
    for dy in my:
        if y + dy in dpy or y - dy in dpy:
            dpy[y] = True
if x in dpx and y in dpy:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s, (x, y) = raw_input().split('T'), map(int, raw_input().split())
cx, cy = len(s[0]), 0
for _ in [len(_) for _ in s[::2]][1:][::-1]:
    cx += _ if cx < x else -_
for _ in [len(_) for _ in s[1::2]][::-1]:
    cy += _ if cy < y else -_
print 'Yes' if (cx, cy) == (x, y) else 'No'

Submission status: Wrong Answer

Solution code:
s=input().split('T')
p=list(map(int,input().split()))
mv=[len(i) for i in s]
d=[[],[]]
for i in range(len(mv)):
    d[i&1].append(mv[i])
t=[0,0]
k=0
x=d[0].copy()
y=d[1].copy()
while x!=[]:
    if t[0]>p[0]:t[0]-=x.pop()
    else:t[0]+=x.pop()
while y!=[]:
    if t[1] > p[1]:
        t[1] -= y.pop()
    else:t[1] += y.pop()
print(['No','Yes'][p==t])

Submission status: Wrong Answer

Solution code:
import itertools
s=list(raw_input())
x,y=map(int,raw_input().split())
#print s
flag=0
sx=[]
sy=[]
t_cnt=0
for i in s:

	if i=="T":
		if flag==0:
			sx.append(t_cnt)
			t_cnt=0
		else:
			sy.append(t_cnt)
			t_cnt=0
		flag=(flag+1)%2
	else:
		t_cnt+=1
else:
	if flag==0:
		sx.append(t_cnt)
	else:
		sy.append(t_cnt)

#print sx
#print sy
len_sx=len(sx)
len_sy=len(sy)


t_l1=list(itertools.product((-1,1),repeat=len_sx))
t_l2=list(itertools.product((-1,1),repeat=len_sy))
#print t_l1
#print t_l2

a=[]
for i in t_l1:
	t_sum=0
	for k,m in zip(sx,i):
		t_sum+=k*m
	a.append(t_sum)

#print a

b=[]
for i in t_l2:
	t_sum=0
	for k,m in zip(sy,i):
		t_sum+=k*m
	b.append(t_sum)

#print b


if x in a and y in b:
	print "Yes"
else:
	print "No"

Submission status: Wrong Answer

Solution code:
s, (x, y) = raw_input().split('T'), map(int, raw_input().split())
xl, yl = [len(_) for _ in s[::2]][::-1], [len(_) for _ in s[1::2]][::-1]
cx, cy = 0, 0
for _ in xl:
    cx += _ if cx < x else -_
for _ in yl:
    cy += _ if cy < y else -_
print 'Yes' if (cx, cy) == (x, y) else 'No'

Submission status: Wrong Answer

Solution code:
s=input()
p=list(map(int,input().split()))
t=[0,0]
k=0
for i in s:
    if i=='T':k^=1
    else:
        if t[k]>p[k]:t[k]-=1
        else:t[k]+=1
print(['No','Yes'][p==t])

Submission status: Wrong Answer

Solution code:
S = input()
x, y = list(map(int, input().split()))
# S = "FTFFFTTFFTFFTFFTFFF"
# x, y = 4, -1
lst = list(map(len, S.split("T")))
e = lst[0::2] # e = [1, 3]
o = lst[1::2]
xl = [0]
yl = [0]
for num in e:
    xl = list(set([xl[i]+num for i in range(len(xl))] + [xl[i]-num for i in range(len(xl))]))
if (x not in xl):
    print("No")
else:
    for num in o:
        yl = list(set([yl[i]+num for i in range(len(yl))] + [yl[i]-num for i in range(len(yl))]))
    if (y not in yl):
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
S = input()
x, y = list(map(int, input().split()))
# S = "FTFFFTTFFTFFTFFTFFF"
# x, y = 4, -1
lst = list(map(len, S.split("T")))
e = lst[0::2] # e = [1, 3]
o = lst[1::2]
xl = [0]
yl = [0]
for num in e:
    xl = list(set([xl[i]+num for i in range(len(xl))] + [xl[i]-num for i in range(len(xl))]))
if (x not in xl):
    print("No")
    exit()
for num in o:
    yl = list(set([yl[i]+num for i in range(len(yl))] + [yl[i]-num for i in range(len(yl))]))
if (y not in yl):
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
S = input()
x, y = list(map(int, input().split()))
# S = "FTFFFTTFFTFFTFFTFFF"
# x, y = 4, -1
lst = list(map(len, S.split("T")))
e = lst[0::2] # e = [1, 3]
o = lst[1::2]
xl = [0]
yl = [0]
for num in e:
    xl = list(set([xl[i]+num for i in range(len(xl))] + [xl[i]-num for i in range(len(xl))]))
if (x not in xl):
    print("No")
    for num in o:
        yl = list(set([yl[i]+num for i in range(len(yl))] + [yl[i]-num for i in range(len(yl))]))
    if (y not in yl):
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
S = input()
x, y = list(map(int, input().split()))
# S = "FTFFFTTFFTFFTFFTFFF"
# x, y = 4, -1
lst = list(map(len, S.split("T")))
e = lst[0::2] # e = [1, 3]
o = lst[1::2]
xl = [0]
yl = [0]
for num in e:
    xl = list(set([xl[i]+num for i in range(len(xl))] + [xl[i]-num for i in range(len(xl))]))
if (x not in xl):
    print("No")
for num in o:
    yl = list(set([yl[i]+num for i in range(len(yl))] + [yl[i]-num for i in range(len(yl))]))
if (y not in yl):
    print("No")
print("Yes")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from itertools import accumulate
s=input()
x,y=map(int,input().split())
tmp=s.split('T')
xm=[]
ym=[]
for i in range(len(tmp)):
    if i%2==0:
        xm.append(len(tmp[i]))
    else:
        ym.append(len(tmp[i]))
if s[0]=='F':
    x-=xm[0]
    xm[0]=0
xm=[0]+list(accumulate(xm))
ym=[0]+list(accumulate(ym))
Dx=(xm[-1]-x)/2.0
Dy=(ym[-1]-y)/2.0
if Dx!=(xm[-1]-x)//2 or Dy!=(ym[-1]-y)//2:
    print('No')
    exit()
f=[False,False]
for i in range(len(xm)):
    for j in range(i,len(xm)):
        if xm[j]-xm[i]==Dx:
            f[0]=True
            break
for i in range(len(ym)):
    for j in range(i,len(ym)):
        if ym[j]-ym[i]==Dy:
            f[1]=True
            break
print('Yes' if f[0] and f[1] else 'No')

Submission status: Wrong Answer

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

def no():
    print("No")
    return

def main():
    s = input()
    x, y = list(map(int, input().split()))
    x_start = 0
    f_count = 0
    x_dirs = []
    y_dirs = []
    is_x = True # xを向いてるか
    t_exist = False
    for c in s:
        if c == "F":
            f_count += 1
            continue
        # T
        if f_count > 0:
            if is_x:
                if t_exist:
                    x_dirs.append(f_count)
                else:
                    x_start = f_count
            else:
                y_dirs.append(f_count)
        t_exist = True
        is_x = not is_x
        f_count = 0
        continue
    if f_count > 0:
        if is_x:
            x_dirs.append(f_count)
        else:
            y_dirs.append(f_count)

    memo_x = [{} for _ in range(len(x_dirs)+1)]
    memo_y = [{} for _ in range(len(y_dirs)+1)]
    memo_x[0][x_start] = True
    memo_y[0][0] = True

    for i, dx in enumerate(x_dirs):
        for j in memo_x[i]:
            memo_x[i+1][j-dx] = True
            memo_x[i+1][j+dx] = True
    for i, dy in enumerate(y_dirs):
        for j in memo_y[i]:
            memo_y[i+1][j-dy] = True
            memo_y[i+1][j+dy] = True

    # print(x_dirs, y_dirs)
    # print(memo_x)
    # print(memo_y)

    if x not in memo_x[len(x_dirs)]:
        return no()
    if y not in memo_y[len(y_dirs)]:
        return no()
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from itertools import accumulate
s=input()
x,y=map(int,input().split())
tmp=s.split('T')
xm=[0]
ym=[0]
for i in range(len(tmp)):
    if i%2==0:
        xm.append(len(tmp[i]))
    else:
        ym.append(len(tmp[i]))
if s[0]=='F':
    x-=xm[0]
    xm[1]=0
xm=list(accumulate(xm))
ym=list(accumulate(ym))
Dx=(xm[-1]-x)/2.0
Dy=(ym[-1]-y)/2.0
if Dx!=(xm[-1]-x)//2 or Dy!=(ym[-1]-y)//2:
    print('No')
    exit()
f=[False,False]
for i in range(len(xm)):
    for j in range(i,len(xm)):
        if xm[j]-xm[i]==Dx:
            f[0]=True
            break
for i in range(len(ym)):
    for j in range(i,len(ym)):
        if ym[j]-ym[i]==Dy:
            f[1]=True
            break
print('Yes' if f[0] and f[1] else 'No')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from itertools import accumulate
s=input()
x,y=map(int,input().split())
tmp=s.split('T')
xm=[0]
ym=[0]
for i in range(len(tmp)):
    if i%2==0:
        xm.append(len(tmp[i]))
    else:
        ym.append(len(tmp[i]))
if s[0]=='F':
    x-=xm[0]
    xm[0]=0
xm=list(accumulate(xm))
ym=list(accumulate(ym))
Dx=(xm[-1]-x)/2.0
Dy=(ym[-1]-y)/2.0
if Dx!=(xm[-1]-x)//2 or Dy!=(ym[-1]-y)//2:
    print('No')
    exit()
f=[False,False]
for i in range(len(xm)):
    for j in range(i,len(xm)):
        if xm[j]-xm[i]==Dx:
            f[0]=True
            break
for i in range(len(ym)):
    for j in range(i,len(ym)):
        if ym[j]-ym[i]==Dy:
            f[1]=True
            break
print('Yes' if f[0] and f[1] else 'No')