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 = map(int,input().split())
x1 = 0
y1 = []
muki = 0
t = len(s)
x2 = []
for i in range(len(s)):
  a = s[i]
  if a == "F":
    x1 += 1
  else:
    t = i+0
    break
x3 = 0
y2 = 0
for i in range(t,len(s)):
  a = s[i]
  if a == "F":
    if muki%2 == 0:
      x3+= 1
    else:
      y2 += 1
  else:
    if muki%2 == 0:
      if x3 != 0:
        x2.append(x3)
      x3 = 0
      muki +=1
    else:
      if y2 != 0:
        y1.append(y2)
      y2 = 0
      muki += 1
if x3 != 0:
   x2.append(x3)
if y2 != 0:
   y1.append(y2)
ansx = set([x1])
for i in x2:
  g = len(ansx)
  ansx2 = list(ansx)
  for j in range(g):
    ansx.add(ansx2[j]+i)
    ansx.add(ansx2[j]-i)
ansy = set([0])
for i in y1:
  g = len(ansy)
  ansy2 = list(ansy)
  for j in range(g):
    ansy.add(ansy2[j]+i)
    ansy.add(ansy2[j]-i)
if (x in ansx and y in ansy):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
x1 = 0
y1 = 0
muki = 0
t = len(s)
for i in range(len(s)):
  a = s[i]
  if a == "F":
    x1 += 1
  else:
    t = i+0
    break
x2 = 0
for i in range(t,len(s)):
  a = s[i]
  if a == "F":
    if muki%2 == 0:
      x2+= 1
    else:
      y1 += 1
  else:
    muki +=1
if (x1 +x2 == x and y1 == y):
  print("Yes")
elif(x1 -x2 == x and y1 == y):
  print("Yes")
elif(x1 -x2 == x and y1 == -y):
  print("Yes")
elif (x1 +x2 == x and y1 == -y):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
# cook your dish here
s=list(input())
x,y = map(int,input().split())
s.append('T')
n = len(s)
d = 0
c = 0
k = 1
xa = {0}
ya = {0}

while d <= n-1:
    if s[d] == 'F':
        c += 1
        d += 1
    else:
        if k == 1:
            xb = set()
            for xx in xa:
                xb.add(xx + c)
                xb.add(xx-c)
                xa = xb
        else:
            yb = set()
            for yy in ya:
                yb.add(yy+c)
                yb.add(yy-c)
                ya = yb
        c = 0
        d += 1
        k = k * (-1)
if x in xa and y in ya:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

main()

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
s = input()
x,y = (int(i) for i in input().split())
dx,dy,num,num2 = [0],[0],0,0
for i in range(len(s)):
	if s[i]=="F" and i!=len(s)-1: num+=1
	else:
		if i==len(s)-1 and s[-1]=="F": num+=1
		num2,d2 = num2+1,[]
		if num2%2==1:
			for j in dx:
				d2.append(j+num)
				d2.append(j-num)
			dx = deepcopy(d2)
		else:
			for j in dy:
				d2.append(j+num)
				d2.append(j-num)
			dy = deepcopy(d2)
		num = 0
if (x in dx) and (y in dy): print("Yes")
else: print("No")

Submission status: Wrong Answer

Solution code:

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

point = [0,0]
xd, yd = 1,0

for i in s:
    if i == "F":
        point[0] += xd
        point[1] += yd
    else:
        if xd == 0:
            yd = 0
            if x-point[0] >= 0:
                xd = 1
            else:
                xd = -1
        else:
            xd = 0
            if y-point[1] >= 0:
                yd = 1
            else:
                yd = -1            
if point == [x,y]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:

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

point = [0,0]
xd, yd = 1,0

direction = [[1,0],[0,1],[-1,0],[0,-1]]
for i in s:
    if i == "F":
        point[0] += xd
        point[1] += yd
    else:
        if xd == 0:
            yd = 0
            if x-point[0] >= 0:
                xd = 1
            else:
                xd = -1
        elif yd == 0:
            xd = 0
            if y-point[1] >= 0:
                yd = 1
            else:
                yd = -1            
if point == [x,y]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = raw_input()
tx, ty = map(int, raw_input().split())
xs, ys = [], []
for i, l in enumerate(map(len, s.split("T"))):
    if i % 2 == 0:
        xs.append(l)
    else:
        ys.append(l)
xs = sorted(xs)[::-1]
ys = sorted(ys)[::-1]
for x in xs:
    tx += (2*(tx < 0) - 1) * x
for y in ys:
    ty += (2*(ty < 0) - 1) * y
print "Yes" if ((tx == 0) and (ty == 0)) else "No"

Submission status: Wrong Answer

Solution code:
s = input()
T = 0
F = 0
for i in s:
    if i == "F":
        F += 1
    else:
        T += 1

x, y = map(int, input().split())
ff = abs(x) + abs(y)
if x > 0 and y > 0 and ff == F and T == 1:
    print("Yes")
elif x > 0 and y == 0 and ff == F and T == 0:
    print("Yes")
elif x > 0 and y < 0 and ff == F and T == 1:
    print("Yes")
elif x == 0 and y > 0 and ff == F and T == 2:
    print("Yes")
elif x == 0 and y == 0 and ff == 0 and T == 0:
    print("Yes")
elif x == 0 and y < 0 and ff == F and T == 1:
    print("Yes")
elif x < 0 and y > 0 and ff == F and T == 2:
    print("Yes")
elif x < 0 and y == 0 and ff == F and T == 3:
    print("Yes")
elif x < 0 and y == 0 and ff == F and T == 3:
    print("Yes")
elif ff > F:
    print("No")
elif x > 0:
    F -= ff
    if y > 0 or y < 0:
        T -= 1
        if T % 1 == 0 and F % 2 == 0:
            print("Yes")
        else:
            print("No")
    elif y == 0:
        if T % 2 == 0 and F % 2 == 0:
            print("Yes")
        else:
            print("No")
elif x == 0:
    F -= ff
    if y > 0 or y < 0:
        T -= 1
        if T % 1 == 0 and F % 2 == 0:
            print("Yes")
        else:
            print("No")
    elif y == 0:
        if T % 2 == 0 and F % 2 == 0:
            print("Yes")
elif x < 0:
    F -= ff
    T -= 2
    if y > 0 or y < 0:
        if T % 2 == 0 and F % 2 == 0:
            print("Yes")
        else:
            print("No")
    elif y == 0:
        if T % 2 == 0 and F % 2 == 0:
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
s = input()
T = 0
F = 0
for i in s:
    if i == "F":
        F += 1
    else:
        T += 1

x, y = map(int, input().split())
ff = abs(x) + abs(y)
if x > 0 and y > 0 and ff == F and T == 1:
    print("Yes")
elif x > 0 and y == 0 and ff == F and T == 0:
    print("Yes")
elif x > 0 and y < 0 and ff == F and T == 1:
    print("Yes")
elif x == 0 and y > 0 and ff == F and T == 2:
    print("Yes")
elif x == 0 and y == 0 and ff == 0 and T == 0:
    print("Yes")
elif x == 0 and y < 0 and ff == F and T == 1:
    print("Yes")
elif x < 0 and y > 0 and ff == F and T == 2:
    print("Yes")
elif x < 0 and y == 0 and ff == F and T == 3:
    print("Yes")
elif x < 0 and y == 0 and ff == F and T == 3:
    print("Yes")
elif ff > F:
    print("No")
elif x > 0:
    F -= ff
    if y > 0 or y < 0:
        T -= 1
        if T % 1 == 0 and F % 2 == 0:
            print("Yes")
        else:
            print("No")
    elif y == 0:
        if T % 2 == 0 and F % 2 == 0:
            print("Yes")
        else:
            print("No")
elif x == 0:
    F -= ff
    if y > 0 or y < 0:
        T -= 1
        if T % 1 == 0 and F % 2 == 0:
            print("Yes")
        else:
            print("No")
    elif y == 0:
        if T % 2 == 0 and F % 2 == 0:
            print("Yes")
elif x < 0:
    F -= ff
    T -= 2
    if y > 0 or y < 0:
        if T % 2 == 0 and F % 2 == 0:
            print("Yes")
        else:
            print("No5")
    elif y == 0:
        if T % 2 == 0 and F % 2 == 0:
            print("Yes")
        else:
            print("No6")

Submission status: Wrong Answer

Solution code:
s = input()
T = 0
F = 0
for i in s:
    if i == "F":
        F += 1
    else:
        T += 1

x, y = map(int, input().split())
ff = x + y
if ff > F:
    print("No")
elif (F - ff) % 2 != 0:
    print("No")
elif x == 0 and y != 0 and F % 2 == 0:
    print("No")
elif x != 0 and y == 0 and F % 2 != 0:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
# T(ターン)で区切る
s = input().split("T")
x, y = ([abs(int(i)) for i in input().split()])

# x方向の移動量とy方向の移動量をまとめる
movex = []
movey = []

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

# 最終目標地へ到達可能か調べる


def t_dfs(move, target):
    move.sort(reverse=True)
    for dx in move:
        if target > 0:
            target -= dx
        else:
            target += dx

    return target == 0


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

Submission status: Wrong Answer

Solution code:
# T(ターン)で区切る
s = input().split("T")
x, y = ([abs(int(i)) for i in input().split()])

# x方向の移動量とy方向の移動量をまとめる
movex = []
movey = []

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

# 最終目標地へ到達可能か調べる


def t_dfs(move, target):
    move.sort()
    for dx in move:
        if target > 0:
            target -= dx
        else:
            target += dx

    return target == 0


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

Submission status: Wrong Answer

Solution code:
# T(ターン)で区切る
s = input().split("T")
x, y = ([int(i) for i in input().split()])

# x方向の移動量とy方向の移動量をまとめる
movex = []
movey = []

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

# 最終目標地へ到達可能か調べる


def t_dfs(move, target):
    move.sort()
    for dx in move:
        if target > 0:
            target -= dx
        else:
            target += dx

    return target == 0


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

Submission status: Wrong Answer

Solution code:
# T(ターン)で区切る
s = input().split("T")
x, y = ([int(i) for i in input().split()])

# x方向の移動量とy方向の移動量をまとめる
movex = []
movey = []

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

# 最終目標地へ到達可能か調べる
def t_dfs(move, target):
    move.sort()
    for dx in move:
        if target > 0:
            target -= dx
        else:
            target += dx

    return target == 0


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

Submission status: Wrong Answer

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

movex = []
movey = []

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


def t_dfs(move, target):
    move.sort()
    for dx in move:
        if target > 0:
            target - dx
        else:
            target + dx

    return target == 0


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

Submission status: Wrong Answer

Solution code:
import numpy as np
s = list(input())
target = np.array([int(i) for i in input().split()])
# 右 : 0 下 : 1 左 : 2 上 :3
direction = np.array([[1, 0], [0, -1], [-1, 0], [0, 1]])


queue = [[np.array([0, 0]), 0, s]]
flag = False

while queue:
    state, now_d, s = queue.pop(0)

    print(target, state, s)

    if len(s) == 0:
        if np.allclose(target, state):
            flag = True
            break
        else:
            continue

    operation = s[0]

    diff = target - state

    if operation == "F":
        next_state = state + direction[now_d]
        queue.append([next_state, now_d, s[1:]])
    elif operation == "T":
        queue.append([state, (now_d+1) % 4, s[1:]])
        queue.append([state, (now_d-1) % 4, s[1:]])

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

Submission status: Wrong Answer

Solution code:
import copy
S = input()
x,y = map(int,input().split())

if 'T' not in S:
    print('Yes' if x==len(S) and y==0 else 'No')
    exit()

sp = S.split('T')
x -= len(sp[0])

v_moves = []
h_moves = []
for i,s in enumerate(sp[1:]):
    if not s: continue
    if i%2==0:
        v_moves.append(len(s))
    else:
        h_moves.append(len(s))

if not h_moves:
    if x != 0:
        print('No')
        exit()
else:
    hs = set([h_moves[0], -h_moves[0]])
    for h in h_moves[1:]:
        tmp = copy.copy(hs)
        for h2 in hs:
            tmp.add(h2 + h)
            tmp.add(h2 - h)
        hs = tmp
        hs.add(h)
        hs.add(-h)
    if x not in hs:
        print('No')
        exit()

if not v_moves:
    if y != 0:
        print('No')
        exit()
else:
    vs = set([v_moves[0], -v_moves[0]])
    for v in v_moves[1:]:
        tmp = copy.copy(vs)
        for v2 in vs:
            tmp.add(v2 + v)
            tmp.add(v2 - v)
        vs = tmp
        vs.add(v)
        vs.add(-v)
    if y not in vs:
        print('No')
        exit()

#print(hs,vs)
#print(x,y)

print('Yes')

Submission status: Wrong Answer

Solution code:
import copy
S = input()
x,y = map(int,input().split())

if 'T' not in S:
    print('Yes' if x==len(S) and y==0 else 'No')
    exit()

sp = S.split('T')
x -= len(sp[0])

v_moves = []
h_moves = []
for i,s in enumerate(sp[1:]):
    if not s: continue
    if i%2==0:
        v_moves.append(len(s))
    else:
        h_moves.append(len(s))

#print(h_moves,v_moves)

hs = set()
for h in h_moves:
    hs.add(h)
    hs.add(-h)
    tmp = copy.copy(hs)
    for h2 in hs:
        tmp.add(h2 + h)
        tmp.add(h2 - h)
    hs = tmp
if not hs:
    hs.add(0)

vs = set()
for v in v_moves:
    vs.add(v)
    vs.add(-v)
    tmp = copy.copy(vs)
    for v2 in vs:
        tmp.add(v2 + v)
        tmp.add(v2 - v)
    vs = tmp
if not vs:
    vs.add(0)

#print(hs,vs)
#print(x,y)

print('Yes' if x in hs and y in vs else 'No')

Submission status: Wrong Answer

Solution code:
s = list(input())
l = list(map(int,input().split()))
x,y = l[0],l[1]
rbx = 0
rby = 0
drc = 0
vecx = [1,0,-1,0]
vecy = [0,1,0,-1]
for i in range(len(s)):
    if s[i] == "F":
        rbx += vecx[drc]
        rby += vecy[drc]
    else:
        if rbx < x:
            if rby < y:
                if drc == 0 or drc == 2:
                    drc = 1
                else:
                    drc = 0
            else:
                if drc == 0 or drc == 2:
                    drc = 3
                else:
                    drc = 0
        else:
            if rby < y:
                if drc == 0 or drc == 2:
                    drc = 1
                else:
                    drc = 2
            else:
                if drc == 0 or drc == 2:
                    drc = 3
                else:
                    drc = 2
print("Yes" if (rbx,rby) == (x,y) else "No")

Submission status: Wrong Answer

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

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

x_reachd = {X_command.pop(0)}
y_reachd = {0}
X_command.sort()

for X in X_command:
    tmp = list(x_reachd)
    for xi in x_reachd:
        tmp.append(xi + X)
        tmp.append(xi - X)
    x_reachd = set(tmp)

for Y in Y_command:
    tmp = list(y_reachd)
    for yi in y_reachd:
        tmp.append(yi + Y)
        tmp.append(yi - Y)
    y_reachd = set(tmp)


if x in x_reachd and y in y_reachd:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

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

nx = X_command.pop(0)
ny = 0

for xi in X_command:
    if nx > x:
        nx -= xi
    else:
        nx += xi

for yi in Y_command:
    if ny > y:
        ny -= yi
    else:
        ny += yi

if nx == x and ny == y:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import deque

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

   Fcount = 0
   ff = 0
   Tcount = 0
   S = []
   for ss in s:
      if ss == "F":
         if (Tcount%2==0)and(Tcount!=0):
            S.append("t")
         elif Tcount!=0:
            S.append("T")
         Fcount += 1
         ff += 1
         Tcount = 0
      elif ss=="T":
         if ff!=0:
            S.append(str(ff))
         Tcount += 1
         ff = 0
   if ff!=0:
      S.append(str(ff))
   if Fcount < (abs(x)+abs(y)):
      return "No"

   # BFS
   k = len(S)
   q = deque([[0,0,1,0,0]])
   while q!=deque([]):
      xx,yy,vx,vy,now = q.popleft()
      if (xx==x)and(yy==y)and(now==k):
         return "Yes"
      elif now==k:
         continue
      else: #now != k
         if S[now] == "T":
            if vx == 0:
               if ([xx,yy,1,0,now+1] in q)==False:
                  q.append([xx,yy,1,0,now+1])
               if ([xx,yy,-1,0,now+1] in q)==False:
                  q.append([xx,yy,-1,0,now+1])
            elif vy == 0:
               if ([xx,yy,0,1,now+1] in q)==False:
                  q.append([xx,yy,0,1,now+1])
               if ([xx,yy,0,-1,now+1] in q)==False:
                  q.append([xx,yy,0,-1,now+1])
         elif S[now] == "t":
            if ([xx,yy,vx,vy,now+1] in q)==False:
               q.append([xx,yy,vx,vy,now+1])
            if ([xx,yy,vx,vy,now+1] in q)==False:
               q.append([xx,yy,-vx,-vy,now+1])
         else :
            if ( [xx+int(S[now])*vx,yy+int(S[now])*vy,vx,vy,now+1] in q)==False:
               q.append([xx+int(S[now])*vx,yy+int(S[now])*vy,vx,vy,now+1])
   return "No"


print(main())

Submission status: Wrong Answer

Solution code:
from collections import deque
def main():
   s = input()
   x,y = map(int, input().split())

   Fcount = 0
   ff = 0
   Tcount = 0
   S = ""
   for ss in s:
      if ss == "F":
         if (Tcount%2==0)and(Tcount!=0):
            S += "t"
         elif Tcount!=0:
            S += "T"
         Fcount += 1
         ff += 1
         Tcount = 0
      elif ss=="T":
         if ff!=0:
            S += str(ff)
         Tcount += 1
         ff = 0
   if ff!=0:
      S += str(ff)
   if Fcount < (abs(x)+abs(y)):
      return "No"

   # BFS
   k = len(S)
   q = deque([[0,0,1,0,0]])
   while q!=deque([]):
      xx,yy,vx,vy,now = q.popleft()
      if (xx==x)and(yy==y)and(now==k):
         return "Yes"
      elif now==k:
         continue
      else: #now != k
         if S[now] == "T":
            if vx == 0:
               q.append([xx,yy,1,0,now+1])
               q.append([xx,yy,-1,0,now+1])
            if vy == 0:
               q.append([xx,yy,0,1,now+1])
               q.append([xx,yy,0,-1,now+1])
         elif S[now] == "t":
            q.append([xx,yy,vx,vy,now+1])
            q.append([xx,yy,-vx,-vy,now+1])
         else :
            q.append([xx+int(S[now])*vx,yy+int(S[now])*vy,vx,vy,now+1])
   return "No"


print(main())

Submission status: Wrong Answer

Solution code:
from collections import deque
def main():
   s = input()
   x,y = map(int, input().split())

   Fcount = 0
   ff = 0
   Tcount = 0
   S = ""
   for ss in s:
      if ss == "F":
         if (Tcount%2==0)and(Tcount!=0):
            S += "TT"
         elif Tcount!=0:
            S += "T"
         Fcount += 1
         ff += 1
         Tcount = 0
      elif ss=="T":
         if ff!=0:
            S += str(ff)
         Tcount += 1
         ff = 0
   if ff!=0:
      S += str(ff)
   if Fcount < (abs(x)+abs(y)):
      return "No"

   # BFS
   k = len(S)
   q = deque([[0,0,1,0,0]])
   while q!=deque([]):
      xx,yy,vx,vy,now = q.popleft()
      if (xx==x)and(yy==y)and(now==k):
         return "Yes"
      elif now==k:
         continue
      else: #now != k
         if S[now] == "T":
            for vv in [1, -1]:
               if vx == 0:
                  q.append([xx,yy,vv,0,now+1])
               elif vy == 0:
                  q.append([xx,yy,0,vv,now+1])
         else :
            q.append([xx+int(S[now])*vx,yy+int(S[now])*vy,vx,vy,now+1])
   return "No"


print(main())

Submission status: Wrong Answer

Solution code:
s = str(input())
x,y = map(int,input().split())
tate = 0
yoko = 0
cou = 0
a = 0

for c in range(len(s)):
    if s[c] == "F":
        cou += 1
    else:
        break
lis = [tate, yoko, cou]

for i in range(len(s)-(cou+1)):
    if s[i + cou + 1] == "F":
        lis[a] += 1
    else:
        a = (a+1)%2

left = cou - lis[1]
right = cou + lis[1]
up = lis[0]
down = -(lis[0])
  # print(left,x,right,down,y,up)
if left <= x and x <= right and down <= y and y <= up:
    if (right - x)%2 == 0 and (up - y)%2 == 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")
  # print(lis)

Submission status: Wrong Answer

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

dx = []
dy = []
hv = 0
for i in s:
    if hv % 2 == 0:
        dx.append(len(i))
    else:
        dy.append(len(i))
    hv += 1
    
nx = dx.pop()
ny = 0

for a in sorted(dx,reverse=True):
    if nx > x:
        nx -= a
    else:
        nx += a

for a in sorted(dy,reverse=True):
    if ny > y:
        ny -= a
    else:
        ny += a

if nx == x and ny == y:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

dx = []
dy = []
hv = 0
for i in s:
    if hv % 2 == 0:
        dx.append(len(i))
    else:
        dy.append(len(i))
    hv += 1   
nx = dx.pop()
ny = 0

for a in sorted(dx,reverse=True):
    if nx >= x:
        nx -= a
    else:
        nx += a

for a in sorted(dy,reverse=True):
    if ny >= y:
        ny -= a
    else:
        ny += a

if nx == x and ny == y:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

A = [len(i) for i in s if len(i) != 0]
dx = []
dy = []

for i in range(len(A)):
    if i % 2 == 0:
        dx.append(A[i])
    else:
        dy.append(A[i])
dx.reverse()
dy.reverse()

if f[0] == "F":
    nx = dx.pop()
    ny = 0
else:
    nx = 0
    ny = 0
    dx = dy
    dy = dx

dx.sort()
dy.sort()


while dx:
    a = dx.pop()
    if nx >= x:
        nx -= a
    else:
        nx += a

while dy:
    a = dy.pop()
    if ny >= y:
        ny -= a
    else:
        ny += a

if nx == x and ny == y:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

A = [len(i) for i in s if len(i) != 0]
dx = []
dy = []

for i in range(len(A)):
    if i % 2 == 0:
        dx.append(A[i])
    else:
        dy.append(A[i])
dx.reverse()
dy.reverse()

if f[0] == "F":
    nx = dx.pop()
    ny = 0
else:
    nx = 0
    ny = 0
    dx = dy
    dy = dx



while dx:
    a = dx.pop()
    if nx >= x:
        nx -= a
    else:
        nx += a

while dy:
    a = dy.pop()
    if ny >= y:
        ny -= a
    else:
        ny += a

if nx == x and ny == y:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

Linex = []
Liney = []
counter = 0
prev = ''
direct = True
for i in range(len(s)):
    if prev =='':
        prev = s[i]
        counter = 1
    elif prev == s[i]:
        counter += 1
    else:
        if prev == 'F':
            if direct:
                Linex.append(counter)
            else:
                Liney.append(counter)
        else:
            if counter%2 != 0:
                direct = not direct
        prev = s[i]
        counter = 1
    if i == len(s)-1 and s[i] == 'F':
        if direct:
            Linex.append(counter)
        else:
            Liney.append(counter)

if s[0] == 'F':
    x = x-Linex[0]
    Linex.pop(0)

def searchBin(target,listObj):
    if len(listObj) == 0:
        if target == 0:
            return True
        else:
            return False

    sum = 0
    if len(listObj) == 1:
        if abs(target) == listObj[0]:
            return True
        else:
            return False
    else:
        for i in range(len(listObj)):
            workBin = format(i,'b').zfill(len(listObj))
            for j in range(len(listObj)):
                if workBin[j] == '0':
                    sum += listObj[j]
                else:
                    sum -= listObj[j]
            if target == sum:
                return True
        return False

if searchBin(x,Linex) and searchBin(y,Liney):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
print ('Yes')

Submission status: Wrong Answer

Solution code:
import collections as col
s = input()
x,y = map(int,input().split())
col.Counter(s)
lr_check = True
ud_count = []
lr_count = []
F_count = 0

for i in range(len(s)):
    if s[i] == 'T':
        if lr_check == True:
            lr_count.append(F_count)
        else:
            ud_count.append(F_count)
        lr_check = -lr_check
        F_count = 0
    else:
        F_count += 1
        if i == len(s)-1:
            if lr_check == True:
                lr_count.append(F_count)
            else:
                ud_count.append(F_count)
            
if (sum(lr_count) - abs(x))%2 == 0 and (sum(ud_count) - abs(y))%2 == 0:
    print ('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

import sys

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

    nf = s.count('F')
    nt = s.count('T')
    last_f = s.rfind('F')
    if last_f != len(s) - 1:
        nt -= len(s) - last_f
    n = nf - x - y

    if nt % 2 == 0 and n >= 0 and n % 2 == 0:
            print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = str(input())
x,y = map(int,input().split())
n = len(s)
dx = []
dy = []
if s[0] == 'T':
	dx.append(0)
i = 0
counter = 0
check = 1
while i < n:
	if s[i] == 'T' and check == 1:
		dx.append(counter)
		check = check * -1
		counter = 0
	elif s[i] == 'T' and check == -1:
		dy.append(counter)
		check = check * -1
		counter = 0
	elif i == n-1 and check == 1:
		dx.append(counter+1)
	elif i == n-1 and check == -1:
		dy.append(counter+1)
	else:
		counter += 1
	i += 1

nx = len(dx)
xtable = [[False for i in range(2*n+1)] for i in range(nx+1)]
#横軸がx座標(-n<=x<=n)、縦軸が操作回数
xtable[0][n] = True
nextvisit = [n]
for i in range(1,nx+1):
	nv = len(nextvisit)
	for k in range(nv):
		if nextvisit[0]-dx[i-1] >= 0:
			xtable[i][nextvisit[0]-dx[i-1]] = True
			nextvisit.append(nextvisit[0]-dx[i-1])
		if nextvisit[0]+dx[i-1] <= 2*n:
			xtable[i][nextvisit[0]+dx[i-1]] = True
			nextvisit.append(nextvisit[0]+dx[i-1])
		nextvisit.pop(0)

ny = len(dy)
ytable = [[False for i in range(2*n+1)] for i in range(ny+1)]
#横軸がy座標(-n<=y<=n)、縦軸が操作回数
ytable[0][n] = True
nextvisity = [n]
for i in range(1,ny+1):
	nv = len(nextvisity)
	for k in range(nv):
		if nextvisity[0]-dy[i-1] >= 0:
			ytable[i][nextvisity[0]-dy[i-1]] = True
			nextvisity.append(nextvisity[0]-dy[i-1])
		if nextvisity[0]+dy[i-1] <= 2*n:
			ytable[i][nextvisity[0]+dy[i-1]] = True
			nextvisity.append(nextvisity[0]+dy[i-1])
		nextvisity.pop(0)

if xtable[nx][x+n] == True and ytable[ny][y+n] == True:
	print('Yes')
else:
	print('No')

Submission status: Wrong Answer

Solution code:
import sys

def check_ans(s,x):
  res=[0]
  for i in s:
    res = set([x + i for x in res]) | set([x - i for x in res])
    print(res)
  return x in res

S = sys.stdin.readline().strip()
X,Y=map(int,input().split())
d=1
while S and S[0]=='F':
  S=S[1:]
  X-=1
if len(S)==0:
  if X==0 and Y==0:
    print("Yes")
  else:
    print("No")
  sys.exit()

nx=[]
ny=[]
X=abs(X)
Y=abs(Y)

while S:
  step=0
  while S and S[0]=='T':
    d*=-1
    S=S[1:]
  while S and S[0]=='F':
    step+=1
    S=S[1:]
  if step==0:
    break
  if d==1:
    nx.append(step)
  else:
    ny.append(step)

if check_ans(nx,X) and check_ans(ny,Y):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import sys

def check_ans(s,x):
  res=[0]
  for i in s:
    res = set([x + i for x in s]) | set([x - i for x in s])
  return x in res

S = sys.stdin.readline().strip()
X,Y=map(int,input().split())
d=1
while S and S[0]=='F':
  S=S[1:]
  X-=1
if len(S)==0:
  if X==0 and Y==0:
    print("Yes")
  else:
    print("No")
  sys.exit()

nx=[]
ny=[]
X=abs(X)
Y=abs(Y)

while S:
  step=0
  while S and S[0]=='T':
    d*=-1
    S=S[1:]
  while S and S[0]=='F':
    step+=1
    S=S[1:]
  if step==0:
    break
  if d==1:
    nx.append(step)
  else:
    ny.append(step)

if check_ans(nx,X) and check_ans(ny,Y):
  print("Yes")
else:
  print("No")