Problem:


Score : 500 points

Problem Statement

A robot is put at the origin in a two-dimensional plane.
Initially, the robot is facing in the positive x-axis direction.

This robot will be given an instruction sequence s.
s consists of the following two kinds of letters, and will be executed in order from front to back.

F : Move in the current direction by distance 1.

T : Turn 90 degrees, either clockwise or counterclockwise.

The objective of the robot is to be at coordinates (x, y) after all the instructions are executed.
Determine whether this objective is achievable.

Constraints

s consists of F and T.

1 \leq |s| \leq 8 000

x and y are integers.

|x|, |y| \leq |s|

Input

Input is given from Standard Input in the following format:

s
x y

Output

If the objective is achievable, print Yes; if it is not, print No.

Sample Input 1

FTFFTFFF
4 2

Sample Output 1

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T.

Sample Input 2

FTFFTFFF
-2 -2

Sample Output 2

Yes

The objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T.

Sample Input 3

FF
1 0

Sample Output 3

No

Sample Input 4

TF
1 0

Sample Output 4

No

Sample Input 5

FFTTFF
0 0

Sample Output 5

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T.

Sample Input 6

TTTT
1 0

Sample Output 6

No



Sample input:
FTFFTFFF
4 2


Sample output:
Yes

Submission status: Runtime Error

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

S = sys.stdin.buffer.readline().decode().rstrip()
X, Y = list(map(int, sys.stdin.buffer.readline().split()))

# X 軸と Y 軸は独立に考えられる。
d = 0
cnt = 0
xy = [[], []]
for c in S:
    if c == 'F':
        cnt += 1
    else:
        xy[d].append(cnt)
        cnt = 0
        d = d + 1 & 1
xy[d].append(cnt)
X -= xy[0].pop(0)


def can_make(moves, obj):
    obj = 1 << (8000 + obj)
    dp = 1 << 8000
    for mv in moves:
        if mv == 0:
            continue
        dp = (dp << mv) | (dp >> mv)
    return (dp & obj) > 0


ok = can_make(xy[0], X) and can_make(xy[1], Y)
if ok:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

flg = 1
x_list = []
y_list = []
tmp = 0
for i, si in enumerate(s):
    if si == 'F':
        tmp += 1
    else:
        if flg == 1:
            x_list.append(tmp)
        else:
            y_list.append(tmp)
        flg *= -1
        tmp = 0
if flg == 1:
    x_list.append(tmp)
else:
    y_list.append(tmp)

x = sum(x_list) - x
y = sum(y_list) - y
if x % 2 != 0 or y % 2 != 0:
    print('No')
    exit()
x //= 2
y //= 2

if s[0] == 'F':
    x_list.reverse()
    x_list.pop()

dpx = [[0] * (x+1) for _ in range(len(x_list)+1)]
dpx[0][0] = 1
dpy = [[0] * (y+1) for _ in range(len(y_list)+1)]
dpy[0][0] = 1
for i in range(len(x_list)):
    for j in range(x+1):
        if dpx[i][j]:
            dpx[i+1][j] = 1
            if j + x_list[i] <= x:
                dpx[i+1][j+x_list[i]] = 1
for i in range(len(y_list)):
    for j in range(y+1):
        if dpy[i][j]:
            dpy[i+1][j] = 1
            if j + y_list[i] <= y:
                dpy[i+1][j+y_list[i]] = 1

if dpx[-1][-1] and dpy[-1][-1]:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import bisect
from itertools import accumulate

def exist_dif(inputS, difx):
  tmpi = bisect.bisect(inputS,difx//2)
  
  if inputS[0] == difx//2:
    return True  
  
  tmp_acmS = accumulate(inputS[:min(tmpi+1,len(inputS))])
  len_tmp_acmS = len(tmp_acmS)
  for i in range(len_tmp_acmS):
    for j in range(i+1,len_tmp_acmS):
      if tmp_acmS[j]-tmp_acmx[i]==difx//2:
        return True
  return False
        
S = input().split('T')
x,y = map(int,input().split())

if S[0] == 'F':
  iniF = len(S[0])
  xS = sorted([len(s) for s in S[2::2]]) if len(S) > 2 else []
else:
  iniF = 0
  xS = sorted([len(s) for s in S[::2]])
  
yS = sorted([len(s) for s in S[1::2]]) if len(S) > 1 else []

sumxS = sum(xS)
sumyS = sum(yS)

xflag = False
if len(xS) == 0:
  if iniF == x: xflag = True
elif x >=0:
  if sumxS+iniF == x:
    xflag = True
  elif sumxS+iniF > x:
    difx = sumxS - x
    if difx%2==0:
      xflag = exist_dif(xS, difx)              
else:
  if sumxS-iniF == -x:
    xflag = True
  elif sumxS-iniF > -x:
    difx = sumxS-iniF + x
    if difx%2==0:
      xflag = exist_dif(xS, difx)
  
yflag = False
if len(yS) == 0:
  if y == 0:
    yflag = True
elif y >= 0:
  if sumyS == y:
    yflag = True
  elif sumyS > y:
    dify = sumyS - y
    if dify%2==0:
      yfalg = exist_dif(yS, dify)            
else:
  if sumyS == -y:
    yflag = True
  elif sumyS > -y:
    dify = sumyS + y
    if dify%2==0:
      yfalg = exist_dif(yS, dify)     
print('Yes' if xflag==True and yflag==True else 'No')

Submission status: Runtime Error

Solution code:
import bisect
from itertools import accumulate

def exist_dif(inputS, difx):
  tmpi = bisect.bisect(inputS,difx//2)
  
  if inputS[0] == difx//2:
    return True  
  
  tmp_acmS = accumulate(inputS[:min(tmpi+1,len(inputS))])
  len_tmp_acmS = len(tmp_acmS)
  for i in range(len_tmp_acmS):
    for j in range(i+1,len_tmp_acmS):
      if tmp_acmS[j]-tmp_acmx[i]==difx//2:
        return True
  return False
        
S = input().split('T')
x,y = map(int,input().split())

if S[0] == 'F':
  iniF = len(S[0])
  xS = sorted([len(s) for s in S[2::2]]) if len(S) > 2 else []
else:
  iniF = 0
  xS = sorted([len(s) for s in S[::2]])
  
yS = sorted([len(s) for s in S[1::2]]) if len(S) > 1 else []

sumxS = sum(xS)
sumyS = sum(yS)

xflag = False
if x >=0:
  if sumxS+iniF == x:
    xflag = True
  elif sumxS+iniF > x:
    difx = sumxS - x
    if difx%2==0:
      xflag = exist_dif(xS, difx)              
else:
  if sumxS-iniF == -x:
    xflag = True
  elif sumxS-iniF > -x:
    difx = sumxS-iniF + x
    if difx%2==0:
      xflag = exist_dif(xS, difx)
  
yflag = False
if y >= 0:
  if sumyS == y:
    yflag = True
  elif sumyS > y:
    dify = sumyS - y
    if dify%2==0:
      yfalg = exist_dif(yS, dify)            
else:
  if sumyS == -y:
    yflag = True
  elif sumyS > -y:
    dify = sumyS + y
    if dify%2==0:
      yfalg = exist_dif(yS, dify)     
print('Yes' if xflag==True and yflag==True else 'No')

Submission status: Runtime Error

Solution code:
import bisect

def exist_dif(inputS, difx):
  tmpi = bisect.bisect(inputS,difx//2)     
  if inputS[0] == difx//2:
    return True  
  
  tmp_acmS = accumulate(inputS[:min(tmpi+1,len(inputS))])
  len_tmp_acmS = len(tmp_acmS)
  for i in range(len_tmp_acmS):
    for j in range(i+1,len_tmp_acmS):
      if tmp_acmS[j]-tmp_acmx[i]==difx//2:
        return True
  return False
        
S = input().split('T')
x,y = map(int,input().split())


if S[0] == 'F':
  iniF = len(S[0])
  xS = sorted([len(s) for s in S[2::2]]) if len(S) > 2 else []
else:
  iniF = 0
  xS = sorted([len(s) for s in S[::2]])
  
yS = sorted([len(s) for s in S[1::2]]) if len(S) > 1 else []

sumxS = sum(xS)
sumyS = sum(yS)

xflag = False
if x >=0:
  if sumxS+iniF == x:
    xflag = True
  elif sumxS+iniF > x:
    difx = sumxS - x
    if difx%2==0:
      xflag = exist_dif(xS, difx)              
else:
  if sumxS-iniF == -x:
    xflag = True
  elif sumxS-iniF > -x:
    difx = sumxS-iniF + x
    if difx%2==0:
      xflag = exist_dif(xS, difx)
  
yflag = False
if y >= 0:
  if sumyS == y:
    yflag = True
  elif sumyS > y:
    dify = sumyS - y
    if dify%2==0:
      yfalg = exist_dif(yS, dify)            
else:
  if sumyS == -y:
    yflag = True
  elif sumyS > -y:
    dify = sumyS + y
    if dify%2==0:
      yfalg = exist_dif(yS, dify)     
print('Yes' if xflag==True and yflag==True else 'No')

Submission status: Runtime Error

Solution code:
import bisect

def exist_dif(inputS, difx):
  tmpi = bisect.bisect(inputS,difx//2)     
  if inputS[0] == difx//2:
    return True  
  
  tmp_acmS = accumulate(inputS[:tmpi+1])
  for i in range(tmpi+1):
    for j in range(i+1,tmpi+1):
      if tmp_acmS[j]-tmp_acmx[i]==difx//2:
        return True
  return False
        
S = input().split('T')
x,y = map(int,input().split())


if S[0] == 'F':
  iniF = len(S[0])
  xS = sorted([len(s) for s in S[2::2]])
else:
  iniF = 0
  xS = sorted([len(s) for s in S[::2]])
  
yS = sorted([len(s) for s in S[1::2]])

sumxS = sum(xS)
sumyS = sum(yS)
xflag = False

if x >=0:
  if sumxS+iniF == x:
    xflag = True
  elif sumxS+iniF > x:
    difx = sumxS - x
    if difx%2==0:
      xflag = exist_dif(xS, difx)              
else:
  if sumxS-iniF == -x:
    xflag = True
  elif sumxS-iniF > -x:
    difx = sumxS-iniF + x
    if difx%2==0:
      xflag = exist_dif(xS, difx)

yflag = False
if y >= 0:
  if sumyS == y:
    yflag = True
  elif sumyS > y:
    dify = sumyS - y
    if dify%2==0:
      yfalg = exist_dif(yS, dify)            
else:
  if sumyS == -y:
    yflag = True
  elif sumyS > -y:
    dify = sumyS + y
    if dify%2==0:
      yfalg = exist_dif(yS, dify)     
print('Yes' if xflag==True and yflag==True else 'No')

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

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

def main():
    def ok(dir):
        goal = abs(xy[dir])
        over=total[dir]-goal
        if over<0 or over%2:
            return False
        if over==0:
            return True
        over//=2
        dp = [False] * (over + 1)
        dp[0] = True
        for d in dd[dir]:
            for i in range(d, goal + 1):
                dp[i] |= dp[i - d]
            if dp[-1]: return True
        return False

    s = input()[:-1]
    xy = list(map(int, input().split()))

    dd = [[], []]
    total=[0,0]
    dir = 0
    cnt = 0
    first = True
    for c in s:
        if c == "F":
            cnt += 1
        if c == "T":
            if first:
                xy[0] -= cnt
                first = False
            else:
                if cnt: dd[dir].append(cnt)
                total[dir]+=cnt
            dir = 1 - dir
            cnt = 0
    if first:
        xy[0] -= cnt
    else:
        if cnt: dd[dir].append(cnt)
        total[dir] += cnt
    #print(xy, dd)

    for dir in range(2):
        if not ok(dir): no()
    print("Yes")

main()

Submission status: Runtime Error

Solution code:
#FT Robot_2
import numpy as np
s = input()
x, y = map(int, input().split())
x = np.array([x])
y = np.array([y])
L = []
stack = 0
p = np.array([0])
q = np.array([0])

for i in range(len(s)):
    if s[i] == "F":
        stack = stack + 1
    else:
        L.append(stack)
        stack = 0

if stack != 0:
    L.append(stack)

for i in range(len(L)):
    if i == 0:
        p = p + L[i]
    elif i % 2 == 0:
        pa = p + L[i]
        pb = p - L[i]
        p = np.concatenate([pa,pb])
    elif i % 2 == 1:
        qa = q + L[i]
        qb = q - L[i]
        q = np.concatenate([qa,qb])

if np.isin(x,p) and np.isin(y,q):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
#FT Robot_2
import numpy as np
s = input()
x, y = map(int, input().split())
x = np.array([x])
y = np.array([y])
L = []
stack = 0
p = np.array([0])
q = np.array([0])

for i in range(len(s)):
    if s[i] == "F":
        stack = stack + 1
    else:
        L.append(stack)
        stack = 0

if stack != 0:
    L.append(stack)

for i in range(len(L)):
    if i == 0:
        p = p + L[i]
    elif i % 2 == 0:
        pa = p + L[i]
        pb = p - L[i]
        p = np.concatenate([pa,pb])
    elif i % 2 == 1:
        qa = q + L[i]
        qb = q - L[i]
        q = np.concatenate([qa,qb])

if np.isin(x,p) and np.isin(y,q):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    S = input()[:-1]
    GX, GY = map(int, input().split())

    # 連続するFをまとめる ex.)FF->2
    # 連続するTをまとめる ex.)TTT->T
    S_parsed = []
    prev = S[0]
    seq = 1
    for c in S[1:]:
        if c == "F":
            if c == prev:
                seq += 1
            else:
                prev = c
                if seq % 2 == 0:
                    pass
                else:
                    S_parsed.append("T")
                seq = 1
        elif c == "T":
            if c == prev:
                seq += 1
            else:
                S_parsed.append(seq)
                seq = 1
            prev = c
    else:
        if S[-1] == "F":
            S_parsed.append(seq)

    # x,yを分離して考える
    x_move = []
    y_move = []

    dir_x = True
    for c in S_parsed:
        if c == "T":
            dir_x = not dir_x
        else:
            if dir_x:
                x_move.append(c)
            else:
                y_move.append(c)

    # x,y分けて、GX,GYに到達できるかをdpで判定
    dp_x = set()
    if len(x_move) > 0:
        if S[0] != "T":
            # Fから始まる場合は、正の方向からスタート
            dp_x.add(x_move[0])
        else:
            # TTから始まってたら、どっち方向からでもスタートできる
            dp_x.add(x_move[0])
            dp_x.add(-x_move[0])
    else:
        dp_x.add(0)

    for x in x_move[1:]:
        dp_x = {key+x for key in dp_x} | {key-y for key in dp_x}

    dp_y = set()
    if len(y_move) == 0:
        dp_y.add(0)
    else:
        dp_y.add(y_move[0])
        dp_y.add(-y_move[0])
    for y in y_move[1:]:
        dp_y = {key+y for key in dp_y} | {key-y for key in dp_y}

    if GX in dp_x and GY in dp_y:
        print("Yes")
    else:
        print("No")


solve()

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    S = input()[:-1]
    GX, GY = map(int, input().split())

    # 連続するFをまとめる ex.)FF->2
    # 連続するTをまとめる ex.)TTT->T
    S_parsed = []
    prev = S[0]
    seq = 1
    for c in S[1:]:
        if c == "F":
            if c == prev:
                seq += 1
            else:
                prev = c
                if seq % 2 == 0:
                    pass
                else:
                    S_parsed.append("T")
                seq = 1
        elif c == "T":
            if c == prev:
                seq += 1
            else:
                S_parsed.append(seq)
                seq = 1
            prev = c
    else:
        if S[-1] == "F":
            S_parsed.append(seq)

    # x,yを分離して考える
    x_move = []
    y_move = []

    dir_x = True
    for c in S_parsed:
        if c == "T":
            dir_x = not dir_x
        else:
            if dir_x:
                x_move.append(c)
            else:
                y_move.append(c)

    # x,y分けて、GX,GYに到達できるかをdpで判定
    dp_x = {}
    if len(x_move) > 0:
        if S[0] != "T":
            # Fから始まる場合は、正の方向からスタート
            dp_x.add(x_move[0])
        else:
            # TTから始まってたら、どっち方向からでもスタートできる
            dp_x.add(x_move[0])
            dp_x.add(-x_move[0])
    else:
        dp_x.add(0)

    for x in x_move[1:]:
        dp_x = {key+x for key in dp_x} | {key-y for key in dp_x}

    dp_y = {}
    if len(y_move) == 0:
        dp_y.add(0)
    else:
        dp_y.add(y_move[0])
        dp_y.add(-y_move[0])
    for y in y_move[1:]:
        dp_y = {key+y for key in dp_y} | {key-y for key in dp_y}

    if GX in dp_x and GY in dp_y:
        print("Yes")
    else:
        print("No")


solve()

Submission status: Runtime Error

Solution code:
from collections import defaultdict
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    S = input()[:-1]
    GX, GY = map(int, input().split())

    S_parsed = []
    prev = S[0]
    seq = 1
    for c in S[1:]:
        if c == "F":
            if c == prev:
                seq += 1
            else:
                prev = c
                if seq % 2 == 0:
                    pass
                else:
                    S_parsed.append("T")
                seq = 1
        elif c == "T":
            if c == prev:
                seq += 1
            else:
                S_parsed.append(seq)
                seq = 1
            prev = c
    else:
        if S[-1] == "F":
            S_parsed.append(seq)

    x_move = []
    y_move = []

    dir_x = True
    for c in S_parsed:
        if c == "T":
            dir_x = not dir_x
        else:
            if dir_x:
                x_move.append(c)
            else:
                y_move.append(c)

    dp_x = defaultdict(bool)
    if len(x_move) > 0:
        dp_x[x_move[0]] = True
    else:
        dp_x[0] = True

    for x in x_move[1:]:
        tmp = defaultdict(bool)
        for key, val in dp_x.items():
            tmp[key+x] = True
            tmp[key-x] = True
        dp_x = tmp

    dp_y = defaultdict(bool)
    if y_move:
        dp_y[0] = True
    else:
        dp_y[y_move[0]] = True
        dp_y[-y_move[0]] = True
        for y in y_move[1:]:
            tmp = defaultdict(bool)
            for key, val in dp_y.items():
                tmp[key+y] = True
                tmp[key-y] = True
            dp_y = tmp

    # print(S_parsed)
    # print(x_move)
    # print(y_move)
    # print(dp_x)
    # print(dp_y)
    if dp_x[GX]and dp_y[GY]:
        print("Yes")
    else:
        print("No")


solve()

Submission status: Runtime Error

Solution code:
from collections import defaultdict
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    S = input()[:-1]
    GX, GY = map(int, input().split())

    S_parsed = []
    prev = S[0]
    seq = 1
    for c in S[1:]:
        if c == "F":
            if c == prev:
                seq += 1
            else:
                prev = c
                if seq % 2 == 0:
                    pass
                else:
                    S_parsed.append("T")
                seq = 1
        elif c == "T":
            if c == prev:
                seq += 1
            else:
                S_parsed.append(seq)
                seq = 1
            prev = c
    else:
        if S[-1] == "F":
            S_parsed.append(seq)

    x_move = []
    y_move = []

    dir_x = True
    for c in S_parsed:
        if c == "T":
            dir_x = not dir_x
        else:
            if dir_x:
                x_move.append(c)
            else:
                y_move.append(c)

    dp_x = defaultdict(bool)
    dp_x[x_move[0]] = True

    for x in x_move[1:]:
        tmp = defaultdict(bool)
        for key, val in dp_x.items():
            tmp[key] = val
            tmp[key+x] = True
            tmp[key-x] = True
        dp_x = tmp

    dp_y = defaultdict(bool)
    dp_y[0] = True
    if len(y_move) > 0:
        for y in y_move:
            tmp = defaultdict(bool)
            for key, val in dp_y.items():
                tmp[key] = val
                tmp[key+y] = True
                tmp[key-y] = True
            dp_y = tmp

    if dp_x[GX]and dp_y[GY]:
        print("Yes")
    else:
        print("No")


solve()

Submission status: Runtime Error

Solution code:
import gc
def dp(l, z):
    length = len(l)
    m=24000
    dp=[[0]*m for i in range(length+1)]
    dp[0][0]=1
    for i in range(1, length+1):
        for j in range(m):
            if dp[i-1][j]==1:
                dp[i][(j+l[i-1])%m]=1
                dp[i][(j-l[i-1])%m]=1
    res = dp[length][z%mod]
    del dp
    gc.collect()
    return res
def solve():
    s=input()
    x, y = map(int, input().split())
    lists = []
    tmp=0
    for si in s:
        if si=='F':
            tmp+=1
        else:
            lists.append(tmp)
            tmp=0
    lists.append(tmp)
    if dp(lists[::2], x) and dp(lists[1::2], y):
        print('Yes')
    else:
        print('No')
solve()

Submission status: Runtime Error

Solution code:
def dp(l, z):
    length = len(l)
    m=16100
    dp=[[0]*m for i in range(length+1)]
    dp[0][0]=1
    for i in range(1, length+1):
        for j in range(m):
            if dp[i-1][j]==1:
                dp[i][(j+l[i-1])%m]=1
                dp[i][(j-l[i-1])%m]=1
    res = dp[length][z%mod]
    del dp
    return res
def solve():
    s=input()
    x, y = map(int, input().split())
    lists = []
    tmp=0
    for si in s:
        if si=='F':
            tmp+=1
        else:
            lists.append(tmp)
            tmp=0
    lists.append(tmp)
    if dp(lists[::2], x) and dp(lists[1::2], y):
        print('Yes')
    else:
        print('No')
solve()

Submission status: Runtime Error

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

while s:
  if s[0] == "F":
    x -= 1
    if len(s) != 1:
      s = s[1:]
    else:
      s = ""

def pm(L):
  DP = 
  for i in range 
for i in range(len(s)):
  pass

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

X = []
Y = []
judge = "x"
l = 0
for i in s:
	if i == "F":
		l += 1
	else:
		if judge == "x":
			X.append(l)
			judge = "y"
		else:
			judge == "y"
			Y.append(l)
			judge = "x"
		l =0

if judge == "x":
	X.append(l)
else:
	Y.append(l)


dx = defaultdict(int)
dx[X[0]] = 1
X.remove(X[0])
for i in range(len(X)):
	D = defaultdict(int)
	for j in dx:
		if dx[j] >= 1:
			D[j + X[i]] = 1
			D[j - X[i]] = 1
	dx = D

dy = defaultdict(int)
dy[Y[0]] = 1
dy[-Y[0]] = 1
Y.remove(Y[0])
for i in range(len(Y)):
	D = defaultdict(int)
	for j in dy:
		if dy[j] >= 1:
			D[j + Y[i]] = 1
			D[j - Y[i]] = 1
	dy = D

if dx[x] == 1 and dy[y] == 1:
	print("Yes")
else:
	print("No")

Submission status: Runtime Error

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

MoveX, MoveY = [], []
dir = "X"
count = 0
for i in range(len(s)): 
    if s[i] == "T":
        if count:
            if dir == "X": MoveX.append(count)
            else: MoveY.append(count)
        count = 0
        dir = ("Y" if dir == "X" else "X")      
    else:
        count += 1
if s[-1] == "F":
    if dir == "X": MoveX.append(count)
    else: MoveY.append(count)

def DP(i, z, Move = list, memo = {}):
    if i == -1: 
        if z == 0: return True
        else: return False
    try:
        return memo[(i, z)]
    except KeyError:
        if DP(i-1, z-Move[i], Move, memo) or DP(i-1, z+Move[i], Move, memo): 
            memo[(i, z)] = True
            return True
        else: 
            memo[(i, z)] = False
            return False

memox, memoy = {}, {}
if DP(len(MoveX)-1, x, MoveX, memox) and DP(len(MoveY)-1, y, MoveY, memoy): print("Yes")
else: print("No")

Submission status: Runtime Error

Solution code:
def inpl(): return [int(i) for i in input().split()]

s = input().split('T')
x, y = inpl()
xi = [len(s[i]) for i in s if i%2 == 0]
yi = [len(s[i]) for i in s if i%2 == 1]

X = (sum(xi)-x)//2
x0 = xi.pop(0) 
Hx = {0: True}
for i in xi:
    for j in Hx.copy().keys():
        Hx[j+i] = True
Y = (sum(yi)-y)//2
Hy = {0: True}
for i in yi:
    for j in Hy.copy().keys():
        Hy[j+i] = True
  
ans = 'Yes'      
if (x0+sum(xi)-x)%2 != 0 or (sum(yi)-y)%2 != 0:
    ans = 'No'
if not Hx.get(X, False) or not Hy.get(Y, False):
    ans = 'No'
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
x, y = map(int, input().split())
m = list(map(len, s.split('T')))
# 最初は右に行くしかない
dp_x = {m[0]}
for i in m[2::2]:
    new_dp = set()
    for v in dp_x:
        new_dp += {v + i, v - i}
    dp_x = new_dp

dp_y = {0}
for i in m[1::2]:
    new_dp = set()
    for v in dp_y:
        new_dp += {v + i, v - i}
    dp_y = new_dp

print('Yes' if x in dp_x and y in dp_y else 'No')

print(dp_x)
print(dp_y)

Submission status: Runtime Error

Solution code:
s=input()
s+='T'
x,y=map(int,input().split())
n=len(s)
direction=0
count=0
X=[]
Y=[]
Y.append(0)
for i in range(n):
    if s[i]=='F':
        count+=1
    else :
        if direction==0:
            X.append(count)
        else :
            Y.append(count)
        count=0
        direction=1-direction

x_dp=[[0]*16001 for i in range(2)]
y_dp=[[0]*16001 for i in range(2)]

x_dp[0][8000+X[0]]=1

for i in range(1,len(X)):
    for j in range(16001):
        if 0<=j-X[i] and j-X[i]<=16000 :
            if x_dp[0][j-X[i]]==1:
                x_dp[1][j]=1
        if 0<=j+X[i] and j+X[i]<=16000 :
            if x_dp[0][j+X[i]]==1:
                x_dp[i][j]=1
    for k in range(16001):
        x_dp[0][k]=x_dp[1][k]
        x_dp[1][k]=0

y_dp[0][8000]=1
for i in range(1,len(Y)):
    for j in range(16001):
        if 0<=j-Y[i] and j-Y[i]<=16000 :
            if y_dp[0][j-Y[i]]==1:
                y_dp[1][j]=1
        if 0<=j+Y[i] and j+Y[i]<=16000 :
            if y_dp[0][j+Y[i]]==1:
                y_dp[1][j]=1
    for k in range(16001):
        y_dp[0][k]=y_dp[1][k]
        y_dp[1][k]=0

if x_dp[0][x+8000]==1 and y_dp[0][y+8000]==1:
    print("Yes")
else :
    print("No")

Submission status: Runtime Error

Solution code:
hoge

Submission status: Runtime Error

Solution code:
s = input().split("T")
x, y = map(int, input().split())
x -= len(s[0])
s.pop(0)

list_yoko = [len(s[i]) for i in range(1, len(s), 2)]
list_tate = [len(s[i]) for i in range(0, len(s), 2)]

set_yoko = {list_yoko[0], -list_yoko[0]}
set_tate = {list_tate[0], -list_tate[0]}

for i in list_yoko[1:]:
	sy = set()
	for j in set_yoko:
		sy |= {j + i, j - i}
	set_yoko = sy

for i in list_tate[1:]:
	st = set()
	for j in set_tate:
		st |= {j + i, j - i}
	set_tate = st

if (x in set_yoko) and (y in set_tate):
	print("Yes")
else:
	print("No")

Submission status: Runtime Error

Solution code:
import sys

s = input().split("T")
x, y = map(int, input().split())
x -= len(s[0])
s.pop(0)

list_yoko = [len(s[i]) for i in range(1, len(s), 2)]
list_tate = [len(s[i]) for i in range(0, len(s), 2)]

set_yoko = {list_yoko[0], -list_yoko[0]}
set_tate = {list_tate[0], -list_tate[0]}

for i in list_yoko[1:]:
	sy = set()
	for j in set_yoko:
		sy |= {j + i, j - i}
	set_yoko = sy

for i in list_tate[1:]:
	st = set()
	for j in set_tate:
		st |= {j + i, j - i}
	set_tate = st

if (x in sy) and (y in st):
	print("Yes")
else:
	print("No")

Submission status: Runtime Error

Solution code:
import sys

import numpy as np

s = raw_input()
x, y = [int(x) for x in raw_input().split(" ")]

s = s + "T"

a = []
b = []

cum_len = 0
turn = 0
for command in s:
    if command == "F":
        cum_len += 1
    elif command == "T":
        (a if turn == 0 else b).append(cum_len)
        turn ^= 1
        cum_len = 0

a0 = a.pop(0)

alpha = abs(x-a0)
beta = abs(y)

targetX = sum(a) - alpha
targetY = sum(b) - beta

def search(a, target):
    forwardTable = np.zeros((len(a), target+1))
    forwardTable[:,0] = 1
    for i_i in xrange(len(a)):
        new_item = a[i_i]
        if i_i == 0:
            forwardTable[i_i, new_item] = 1
            forwardTable[i_i, 2*new_item:2*new_item+1] = 1
        else:
            forwardTable[i_i] += forwardTable[i_i-1]
            if new_item>0:
                forwardTable[i_i,new_item:] += forwardTable[i_i-1,:-new_item]
                forwardTable[i_i,2*new_item:] += forwardTable[i_i-1,:-2*new_item]
        if forwardTable[i_i,-1] > 0:
            forwardTable[-1,-1] = 1
            break

    return (forwardTable[-1,-1]>0)

if (targetX < 0) or (targetY < 0):
    print "No"
    sys.exit()
else:
    if (targetX > 0):
        if not search(a, targetX):
            print "No"
            sys.exit()
    if (targetY > 0):
        if not search(b, targetY):
            print "No"
            sys.exit()
    print "Yes"

Submission status: Runtime Error

Solution code:
import sys

import numpy as np

s = raw_input()
x, y = [int(x) for x in raw_input().split(" ")]

s = s + "T"

a = []
b = []

cum_len = 0
turn = 0
for command in s:
    if command == "F":
        cum_len += 1
    elif command == "T":
        (a if turn == 0 else b).append(cum_len)
        turn ^= 1
        cum_len = 0

a0 = a.pop(0)

alpha = abs(x-a0)
beta = abs(y)

targetX = sum(a) - alpha
targetY = sum(b) - beta

def search(a, target):
    forwardTable = np.zeros((len(a), target+1))
    forwardTable[:,0] = 1
    for i_i in xrange(len(a)):
        new_item = a[i_i]
        if i_i == 0:
            forwardTable[i_i, new_item] = 1
        else:
            forwardTable[i_i] += forwardTable[i_i-1]
            forwardTable[i_i,new_item:] += forwardTable[i_i,:-new_item]
        if forwardTable[i_i,-1] > 0:
            forwardTable[-1,-1] = 1
            break

    return (forwardTable[-1,-1]>0)

if (targetX < 0) or (targetY < 0):
    print "No"
    sys.exit()
else:
    if (targetX > 0):
        if not search(a, targetX):
            print "No"
            sys.exit()
    if (targetY > 0):
        if not search(b, targetY):
            print "No"
            sys.exit()
    print "Yes"

Submission status: Runtime Error

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



for i in range(N):
    if s[i] == "F":
        x -= 1
    else:
        cnt_Y = True
        index = i + 1
        break

steps_X = []
steps_Y = []

while index < N:
    cnt = 0
    for j in range(index, N):
        if s[j] == "F":
            cnt += 1
        else:
            if cnt_Y and cnt != 0:
                steps_Y.append(cnt)
            elif not cnt_Y and cnt != 0:
                steps_X.append(cnt)
            cnt_Y = not cnt_Y
            index = j
            break
    index += 1


K = 8000*2+5
dp = [[False] * (8000*2+1) for _ in range(2)]
dp[0][0] = True


for i, t in enumerate(steps_X):
    trues_p = [idx + t for idx, v in enumerate(dp[i%2]) if v == True]
    trues_n = [idx - t for idx, v in enumerate(dp[i%2]) if v == True]
    for tr in trues_p:
        dp[(i+1)%2][tr] = True
    for tr in trues_n:
        dp[(i+1)%2][tr] = True

if dp[len(steps_X) %2][x] == False:
    print("No")
    import sys
    sys.exit()

dp = [[False] * (8000*2+1) for _ in range(2)]
dp[0][0] = True

for i, t in enumerate(steps_Y):
    trues_p = [idx + t for idx, v in enumerate(dp[i%2]) if v == True]
    trues_n = [idx - t for idx, v in enumerate(dp[i%2]) if v == True]
    for tr in trues_p:
        dp[(i+1)%2][tr] = True
    for tr in trues_n:
        dp[(i+1)%2][tr] = True

if dp[len(steps_Y) %2][y] == False:
    print("No")
    import sys
    sys.exit()

print("Yes")

Submission status: Runtime Error

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



for i in range(N):
    if s[i] == "F":
        x -= 1
    else:
        cnt_Y = True
        index = i + 1
        break

steps_X = []
steps_Y = []

while index < N:
    cnt = 0
    for j in range(index, N):
        if s[j] == "F":
            cnt += 1
        else:
            if cnt_Y and cnt != 0:
                steps_Y.append(cnt)
            elif not cnt_Y and cnt != 0:
                steps_X.append(cnt)
            cnt_Y = not cnt_Y
            index = j
            break
    index += 1

    
K = 8000*2+1
dp = [[False] * (8000*2+1) for _ in range(2)]
dp[0][0] = True


for i, t in enumerate(steps_X):
    trues_p = [idx + t for idx, v in enumerate(dp[i%2]) if v == True]
    trues_n = [idx - t for idx, v in enumerate(dp[i%2]) if v == True]
    for tr in trues_p:
        dp[(i+1)%2][tr] = True
    for tr in trues_n:
        dp[(i+1)%2][tr] = True

if dp[len(steps_X) %2][x] == False:
    print("No")
    import sys
    sys.exit()

dp = [[False] * (8000*2+1) for _ in range(2)]
dp[0][0] = True

for i, t in enumerate(steps_Y):
    trues_p = [idx + t for idx, v in enumerate(dp[i%2]) if v == True]
    trues_n = [idx - t for idx, v in enumerate(dp[i%2]) if v == True]
    for tr in trues_p:
        dp[(i+1)%2][tr] = True
    for tr in trues_n:
        dp[(i+1)%2][tr] = True

if dp[len(steps_Y) %2][y] == False:
    print("No")
    import sys
    sys.exit()

print("Yes")