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:
s=input()
gx,gy=map(int,input().split())
lists=list(s.split("T"))
xlist=[]
ylist=[]
if s[0]=="T":
    for i in range(len(lists)):
        if i%2==0:
            xlist.append(len(lists[i]))
        else:
            ylist.append(len(lists[i]))
elif s[0]=="F":
    for i in range(len(lists)):
        if i%2==0:
            xlist.append(len(lists[i]))
        else:
            ylist.append(len(lists[i]))
    gx-=xlist[0]
    del xlist[0]
for some in xlist:
    some=abs(some)
for some in ylist:
    some=abs(some)
Xsum=sum(xlist)
Ysum=sum(ylist)
if (Xsum+gx)%2!=0 or (Ysum+gy)%2!=0:
    print("No")
else:
    gx1=(Xsum+gx)//2
    gx2=(Xsum-gx)//2
    gy1=(Ysum+gy)//2
    gy2=(Ysum-gy)//2
    dpx=[[False for i in range(8001)] for i in range(len(xlist)+1)]
    dpy=[[False for i in range(8001)] for j in range(len(ylist)+1)]
    #dpx[i][j]でi番目のカードまでを足して、値ｊを取れるか判定する
    dpx[1][xlist[0]]=True
    dpy[1][ylist[0]]=True
    
    for i in range(1,len(xlist)):
        for j in range(8001):
            dpx[i+1][j]=dpx[i][j-xlist[i]] or dpx[i][j]
    for i in range(1,len(ylist)):
        for j in range(8001):
            dpy[i+1][j]=dpy[i][j-ylist[i]] or dpy[i][j]    
            
    if (dpy[len(ylist)][gy1] or dpy[len(ylist)][gy2]) and (dpx[len(xlist)][gx1] or dpx[len(xlist)][gx2]):
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

s = input()
x, y = MAP()

if "T" not in s:
	x_list = [len(s)]
	y_list = []
else:
	F = s.split("T")

	x_list = []
	y_list = []
	for i, n in enumerate(F):
		if i%2 == 0:  # x軸方向
			x_list.append(len(n))
		else:
			y_list.append(len(n))

"""
x_listから順に取り出して右か左に動く．
dp[i][x] := i回目の移動後にx座標がxとなっていることができるか
y軸も同様
"""

x -= x_list.pop(0)  # 最初のFの分だけ右に動く
x_sum = sum(x_list)
y_sum = sum(y_list)


if (x_sum-x)%2 != 0:  # パリティ
  print("No")
  sys.exit()
else:
  n_x = (x_sum-abs(x))//2
if (y_sum-y)%2 != 0:
  print("No")
  sys.exit()
else:
  n_y = (y_sum-abs(y))//2

dp_x = [[False]*(abs(n_x)+1) for _ in range(len(x_list)+1)]
dp_y = [[False]*(abs(n_y)+1) for _ in range(len(x_list)+1)]
dp_x[0][0] = True
dp_y[0][0] = True

for i in range(1, len(x_list)+1):
	for j in range(n_x+1):
		if dp_x[i-1][j]:
			dp_x[i][j] = True
			if j+x_list[i-1] < n_x+1:
				dp_x[i][j+x_list[i-1]] = True

for i in range(1, len(y_list)+1):
	for j in range(n_y+1):
		if dp_y[i-1][j]:
			dp_y[i][j] = True
			if j+y_list[i-1] < n_y+1:
				dp_y[i][j+y_list[i-1]] = True

if dp_x[-1][-1] and dp_y[-1][-1]:
	print("Yes")
else:
	print("No")

Submission status: Runtime Error

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

s = input()
x, y = MAP()

F = s.split("T")

x_list = []
y_list = []
for i, n in enumerate(F):
	if i%2 == 0:  # x軸方向
		x_list.append(len(n))
	else:
		y_list.append(len(n))

"""
x_listから順に取り出して右か左に動く．
dp[i][x] := i回目の移動後にx座標がxとなっていることができるか
y軸も同様
"""

x -= x_list.pop(0)  # 最初のFの分だけ右に動く
x_sum = sum(x_list)
y_sum = sum(y_list)


if (x_sum-x)%2 != 0:  # パリティ
  print("No")
  sys.exit()
else:
  n_x = (x_sum-abs(x))//2
if (y_sum-y)%2 != 0:
  print("No")
  sys.exit()
else:
  n_y = (y_sum-abs(y))//2

dp_x = [[False]*(abs(n_x)+1) for _ in range(len(x_list)+1)]
dp_y = [[False]*(abs(n_y)+1) for _ in range(len(x_list)+1)]
dp_x[0][0] = True
dp_y[0][0] = True

for i in range(1, len(x_list)+1):
	for j in range(n_x+1):
		if dp_x[i-1][j]:
			dp_x[i][j] = True
			if j+x_list[i-1] < n_x+1:
				dp_x[i][j+x_list[i-1]] = True

for i in range(1, len(y_list)+1):
	for j in range(n_y+1):
		if dp_y[i-1][j]:
			dp_y[i][j] = True
			if j+y_list[i-1] < n_y+1:
				dp_y[i][j+y_list[i-1]] = True

if dp_x[-1][-1] and dp_y[-1][-1]:
	print("Yes")
else:
	print("No")

Submission status: Runtime Error

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

s = input()
x, y = MAP()

F = s.split("T")
print(F)
x_list = []
y_list = []
for i, n in enumerate(F):
	if i%2 == 0:  # x軸方向
		x_list.append(len(n))
	else:
		y_list.append(len(n))

"""
x_listから順に取り出して右か左に動く．
dp[i][x] := i回目の移動後にx座標がxとなっていることができるか
y軸も同様
"""

if len(x_list) == 0:
	if x == 0 and y == 0:
		print("Yes")
		sys.exit()
	else:
		print("No")
		sys.exit()

x -= x_list.pop(0)  # 最初のFの分だけ右に動く
x_sum = sum(x_list)
y_sum = sum(y_list)


if (x_sum-x)%2 != 0:  # パリティ
  print("No")
  sys.exit()
else:
  n_x = (x_sum-abs(x))//2
if (y_sum-y)%2 != 0:
  print("No")
  sys.exit()
else:
  n_y = (y_sum-abs(y))//2

dp_x = [[False]*(abs(n_x)+1) for _ in range(len(x_list)+1)]
dp_y = [[False]*(abs(n_y)+1) for _ in range(len(x_list)+1)]
dp_x[0][0] = True
dp_y[0][0] = True

for i in range(1, len(x_list)+1):
	for j in range(n_x+1):
		if dp_x[i-1][j]:
			dp_x[i][j] = True
			if j+x_list[i-1] < n_x+1:
				dp_x[i][j+x_list[i-1]] = True

for i in range(1, len(y_list)+1):
	for j in range(n_y+1):
		if dp_y[i-1][j]:
			dp_y[i][j] = True
			if j+y_list[i-1] < n_y+1:
				dp_y[i][j+y_list[i-1]] = True

if dp_x[-1][-1] and dp_y[-1][-1]:
	print("Yes")
else:
	print("No")

Submission status: Runtime Error

Solution code:
f,*l=map(len,input().split("T"))
x,y=map(int,input().split())
z=8000;bx=1<<f+z;by=1<<z
for dy,dx in zip(*[iter(l)]*2):bx=bx<<dx|bx>>dx;by=by<<dy|by>>dy
print("Yes"*(bx&(1<<x+z) and by&(1<<y+z))or"No")

Submission status: Runtime Error

Solution code:
import sys
s = input()
gx,gy = map(int, input().split(' '))
x_d = [0]
y_d = []
cnt = 0
for i in range(len(s)):
    if s[i] == "T":
        cnt += 1
        if cnt % 2 == 0:
            x_d.append(0)
        elif cnt % 2 == 1:
            y_d.append(0)
    if s[i] == "F":
        if cnt % 2 == 0:
            x_d[-1] += 1
        elif cnt % 2 == 1:
            y_d[-1] += 1
gx -= x_d[0]
del x_d[0]
x_d.append(0)
y_d.append(0)
if (sum(x_d)-gx) % 2 or (sum(y_d)-gy) % 2 or sum(x_d) < abs(gx) or sum(y_d) < abs(gy):
    print("No")
    sys.exit()
x_n = (sum(x_d)-gx)//2
y_n = (sum(y_d)-gy)//2
DPx = [[False for i in range(x_n+2)] for j in range(len(x_d))]
DPy = [[False for i in range(y_n+2)] for j in range(len(y_d))]
for x in DPx:
    x[0] = True
for y in DPy:
    y[0] = True
for i in range(len(x_d)-1):
    for j in range(x_n+2):
        if DPx[i][j]:
            DPx[i+1][j] = True
            if j+x_d[i] <= x_n+1:
                DPx[i+1][j+x_d[i]] = True
for i in range(len(y_d)-1):
    for j in range(y_n+2):
        if DPy[i][j]:
            DPy[i+1][j] = True
            if j+y_d[i] <= y_n+1:
                DPy[i+1][j+y_d[i]] = True
if DPx[len(x_d)-1][x_n] and DPy[len(y_d)-1][y_n]:
    print("Yes")
else:
    print("No")
print(x_d,y_d,x_n,y_n)
print(*DPx,"----",*DPy,sep="\n")

Submission status: Runtime Error

Solution code:
import sys
s = input()
gx,gy = map(int, input().split(' '))
x_d = [0]
y_d = []
cnt = 0
for i in range(len(s)):
    if s[i] == "T":
        cnt += 1
        if cnt % 2 == 0:
            x_d.append(0)
        elif cnt % 2 == 1:
            y_d.append(0)
    if s[i] == "F":
        if cnt % 2 == 0:
            x_d[-1] += 1
        elif cnt % 2 == 1:
            y_d[-1] += 1
x_d.append(0)
y_d.append(0)
if (sum(x_d)-gx) % 2 or (sum(y_d)-gy) % 2:
    print("No")
    sys.exit()
x_n = (sum(x_d)-gx)//2
y_n = (sum(y_d)-gy)//2
DPx = [[False for i in range(x_n+2)] for j in range(len(x_d))]
DPy = [[False for i in range(y_n+2)] for j in range(len(y_d))]
for x in DPx:
    x[0] = True
for y in DPy:
    y[0] = True
for i in range(len(x_d)-1):
    for j in range(x_n+1):
        if DPx[i][j]:
            DPx[i+1][j] = True
            if j+x_d[i] <= x_n+1:
                DPx[i+1][j+x_d[i]] = True
for i in range(len(y_d)-1):
    for j in range(y_n+1):
        if DPy[i][j]:
            DPy[i+1][j] = True
            if j+y_d[i] <= y_n+1:
                DPy[i+1][j+y_d[i]] = True
if DPx[len(x_d)-2][x_n] and DPy[len(y_d)-2][y_n]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys
s = input()
gx,gy = map(int, input().split(' '))
x_d = [0]
y_d = []
cnt = 0
for i in range(len(s)):
    if s[i] == "T":
        cnt += 1
        if cnt % 2 == 0:
            x_d.append(0)
        elif cnt % 2 == 1:
            y_d.append(0)
    if s[i] == "F":
        if cnt % 2 == 0:
            x_d[-1] += 1
        elif cnt % 2 == 1:
            y_d[-1] += 1
x_d.append(0)
y_d.append(0)
if (sum(x_d)-gx) % 2 or (sum(y_d)-gy) % 2:
    print("No")
    sys.exit()
x_n = (sum(x_d)-gx)//2
y_n = (sum(y_d)-gy)//2
DPx = [[False for i in range(x_n+2)] for j in range(len(x_d))]
DPy = [[False for i in range(y_n+2)] for j in range(len(y_d))]
for x in DPx:
    x[0] = True
for y in DPy:
    y[0] = True
for i in range(len(x_d)-1):
    for j in range(x_n+1):
        if DPx[i][j]:
            DPx[i+1][j] = True
            if j+x_d[i] <= x_n+1:
                DPx[i+1][j+x_d[i]] = True
for i in range(len(y_d)-1):
    for j in range(y_n+1):
        if DPy[i][j]:
            DPy[i+1][j] = True
            if j+y_d[i] <= y_n+1:
                DPy[i+1][j+y_d[i]] = True

if DPx[len(x_d)-1][x_n] and DPy[len(y_d)-1][y_n]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys
s = input()
gx,gy = map(int, input().split(' '))
x_d = [0]
y_d = []
cnt = 0
for i in range(len(s)):
    if s[i] == "T":
        cnt += 1
        if cnt % 2 == 0:
            x_d.append(0)
        elif cnt % 2 == 1:
            y_d.append(0)
    if s[i] == "F":
        if cnt % 2 == 0:
            x_d[-1] += 1
        elif cnt % 2 == 1:
            y_d[-1] += 1
x_d.append(0)
y_d.append(0)
if (sum(x_d)-gx) % 2 or (sum(y_d)-gy) % 2:
    print("No")
    sys.exit()
x_n = (sum(x_d)-gx)//2
y_n = (sum(y_d)-gy)//2
DPx = [[False for i in range(x_n+2)] for j in range(len(x_d))]
DPy = [[False for i in range(y_n+2)] for j in range(len(y_d))]
for x in DPx:
    x[0] = True
for y in DPy:
    y[0] = True
for i in range(len(x_d)-1):
    for j in range(x_n+1):
        if DPx[i][j]:
            DPx[i+1][j] = True
            if j+x_d[i] <= x_n:
                DPx[i+1][j+x_d[i]] = True
for i in range(len(y_d)-1):
    for j in range(y_n+1):
        if DPy[i][j]:
            DPy[i+1][j] = True
            if j+y_d[i] <= y_n:
                DPy[i+1][j+y_d[i]] = True

if DPx[len(x_d)-1][x_n] and DPy[len(y_d)-1][y_n]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys
s = input()
gx,gy = map(int, input().split(' '))
x_d = [0]
y_d = []
cnt = 0
for i in range(len(s)):
    if s[i] == "T":
        cnt += 1
        if cnt % 2 == 0:
            x_d.append(0)
        elif cnt % 2 == 1:
            y_d.append(0)
    if s[i] == "F":
        if cnt % 2 == 0:
            x_d[-1] += 1
        elif cnt % 2 == 1:
            y_d[-1] += 1
x_d.append(0)
y_d.append(0)
if (sum(x_d)-gx) % 2 or (sum(y_d)-gy) % 2:
    print("No")
    sys.exit()
x_n = (sum(x_d)-gx)//2
y_n = (sum(y_d)-gy)//2
DPx = [[False for i in range(x_n+1)] for j in range(len(x_d))]
DPy = [[False for i in range(y_n+1)] for j in range(len(y_d))]
for x in DPx:
    x[0] = True
for y in DPy:
    y[0] = True
for i in range(len(x_d)-1):
    for j in range(x_n+1):
        if DPx[i][j]:
            DPx[i+1][j] = True
            if j+x_d[i] <= x_n:
                DPx[i+1][j+x_d[i]] = True
for i in range(len(y_d)-1):
    for j in range(y_n+1):
        if DPy[i][j]:
            DPy[i+1][j] = True
            if j+y_d[i] <= y_n:
                DPy[i+1][j+y_d[i]] = True

if DPx[-2][x_n] and DPy[-2][y_n]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys
s = input()
gx,gy = map(int, input().split(' '))
x_d = [0]
y_d = []
cnt = 0
for i in range(len(s)):
    if s[i] == "T":
        cnt += 1
        if cnt % 2 == 0:
            x_d.append(0)
        elif cnt % 2 == 1:
            y_d.append(0)
    if s[i] == "F":
        if cnt % 2 == 0:
            x_d[-1] += 1
        elif cnt % 2 == 1:
            y_d[-1] += 1
x_d.append(0)
y_d.append(0)
if (sum(x_d)-gx) % 2 or (sum(y_d)-gy) % 2:
    print("No")
    sys.exit()
x_n = (sum(x_d)-gx)//2
y_n = (sum(y_d)-gy)//2
DPx = [[False for i in range(x_n+2)] for j in range(len(x_d))]
DPy = [[False for i in range(y_n+2)] for j in range(len(y_d))]
for x in DPx:
    x[0] = True
for y in DPy:
    y[0] = True
for i in range(len(x_d)-1):
    for j in range(x_n+1):
        if DPx[i][j]:
            DPx[i+1][j] = True
            if j+x_d[i] <= x_n:
                DPx[i+1][j+x_d[i]] = True
for i in range(len(y_d)-1):
    for j in range(y_n+1):
        if DPy[i][j]:
            DPy[i+1][j] = True
            if j+y_d[i] <= y_n:
                DPy[i+1][j+y_d[i]] = True

if DPx[-2][x_n] and DPy[-2][y_n]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys
s = input()
gx,gy = map(int, input().split(' '))
x_d = [0]
y_d = []
cnt = 0
for i in range(len(s)):
    if s[i] == "T":
        cnt += 1
        if cnt % 2 == 0:
            x_d.append(0)
        elif cnt % 2 == 1:
            y_d.append(0)
    if s[i] == "F":
        if cnt % 2 == 0:
            x_d[-1] += 1
        elif cnt % 2 == 1:
            y_d[-1] += 1
x_d.append(0)
y_d.append(0)
if (sum(x_d)-gx) % 2 or (sum(y_d)-gy) % 2:
    print("No")
    sys.exit()
x_n = (sum(x_d)-gx)//2
y_n = (sum(y_d)-gy)//2
DPx = [[False for i in range(x_n+1)] for j in range(len(x_d))]
DPy = [[False for i in range(y_n+1)] for j in range(len(y_d))]
for x in DPx:
    x[0] = True
for y in DPy:
    y[0] = True
for i in range(len(x_d)-1):
    for j in range(x_n+1):
        if DPx[i][j]:
            DPx[i+1][j] = True
            if j+x_d[i] <= x_n:
                DPx[i+1][j+x_d[i]] = True
for i in range(len(y_d)-1):
    for j in range(y_n+1):
        if DPy[i][j]:
            DPy[i+1][j] = True
            if j+y_d[i] <= y_n:
                DPy[i+1][j+y_d[i]] = True

if DPx[len(x_d)-1][x_n] and DPy[len(y_d)-1][y_n]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(s: str, x: int, y: int):
    LENS = len(s)
    s_list = list(map(len,s.split("T")))
    x_s_list = s_list[0::2]
    y_s_list = s_list[1::2]

    x_dp = [[False]*(2*LENS+1) for _ in range(len(x_s_list))]
    ## answer = x_dp[-1][x+LENS]
    for index,count in enumerate(x_s_list):
        ## 最初は
        if index == 0:
            x_dp[index][count+LENS] = True
            continue
        
        for j in range(2*LENS+1):
            if j-count >= 0 and j+count< 2*LENS+1:
                x_dp[index][j] = x_dp[index-1][j-count] or x_dp[index-1][j+count] 
            elif j-count >= 0:
                x_dp[index][j] = x_dp[index-1][j-count]
            elif j+count< 2*LENS+1:
                x_dp[index][j] = x_dp[index-1][j+count]


    y_dp = [[False]*(2*LENS+1) for _ in range(len(y_s_list))]
    for index,count in enumerate(y_s_list):
        ## 最初は
        if index == 0:
            y_dp[index][count+LENS] = True
            y_dp[index][-count+LENS] = True            
            continue
        
        for j in range(2*LENS+1):
            if j-count >= 0 and j+count< 2*LENS+1:
                y_dp[index][j] = y_dp[index-1][j-count] or y_dp[index-1][j+count] 
            elif j-count >= 0:
                y_dp[index][j] = y_dp[index-1][j-count]
            elif j+count< 2*LENS+1:
                y_dp[index][j] = y_dp[index-1][j+count]
    

    if x_dp[-1][x+LENS] and y_dp[-1][y+LENS]:
        print(YES)
    else:
        print(NO)

    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    x = int(next(tokens))  # type: int
    y = int(next(tokens))  # type: int
    solve(s, x, y)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s = input()
x, y = list(map(int, input().split()))
F = [len(fs) for fs in s.split('T')]
Fx = F[0::2]
Fy = F[1::2]

xt2 = sum(Fx)-x
yt2 = sum(Fy)-y
if xt2%2==1 or yt2%2==1:
    print('No')
    exit()

xt = xt2//2
yt = yt2//2

dpx = [False]*(xt+1)
dpx[0] = True
for f in Fx:
    for i in range(xt, f-1, -1): dpx[i] |= dpx[i-f]

dpy = [False]*(yt+1)
dpy[0] = True
for f in Fy:
    for i in range(yt, f-1, -1): dpy[i] |= dpy[i-f]

print('Yes' if dpx[xt] and dpy[yt] else 'No')

Submission status: Runtime Error

Solution code:
s = input()
x, y = list(map(int, input().split()))
F = [len(fs) for fs in s.split('T')]
Fx = F[0::2]
Fy = F[1::2]

xt2 = (sum(Fx)-x)
yt2 = (sum(Fy)-y)
if xt2%2==1 or yt2%2==1:
    print('No')
    exit()

xt = xt2//2
yt = yt2//2

M = 8000
dpx = [False]*M
dpx[0] = True
for f in Fx:
    for i in range(M-1, f-1, -1):
        if dpx[i-f]: dpx[i]=True

dpy = [False]*M
dpy[0] = True
for f in Fy:
    for i in range(M-1, f-1, -1):
        if dpy[i-f]: dpy[i]=True

print('Yes' if dpx[xt] and dpy[yt] else 'No')

Submission status: Runtime Error

Solution code:
import numpy as np
s = list(input())
x, y = map(int, input().split())

X = [0]
Y = [0]

flag = True
tmp = 0
for i in s:
    if i == 'F':
        tmp += 1
    else:
        if flag:
            X.append(tmp)
        else:
            Y.append(tmp)
        tmp = 0
        flag = not flag

if flag:
    X.append(tmp)
else:
    Y.append(tmp)

# print (X)
# print (Y)

x -= X[1]
X[1] = 0

x = abs(x)
y = abs(y)

total_X = sum(X)
total_Y = sum(Y)

lst_X = np.zeros(total_X + 1)
lst_X[0] = 1
for i in X:
    if i == 0:
        continue
    # print (lst_X[i:])
    # print (lst_X[:-i])
    lst_X[i:] = max(lst_X[i:], lst_X[:-i])

# print (lst_X)

lst_Y = np.zeros(total_Y + 1)
lst_Y[0] = 1
for i in Y:
    if i == 0:
        continue
    lst_Y[i:] = max(lst_Y[i:], lst_Y[:-i])

if x > total_X or y > total_Y:
    print ('No')
    exit()

if (total_X - x) % 2 == (total_Y - y) % 2 == 0 and int(lst_X[(total_X - x) // 2]) == 1 and int(lst_Y[(total_Y - y) // 2]) == 1:
    print ('Yes')
else:
    print ('No')

Submission status: Runtime Error

Solution code:
import numpy as np
s = list(input())
x, y = map(int, input().split())

X = [0]
Y = [0]

flag = True
tmp = 0
for i in s:
    if i == 'F':
        tmp += 1
    else:
        if flag:
            X.append(tmp)
        else:
            Y.append(tmp)
        tmp = 0
        flag = not flag

if flag:
    X.append(tmp)
else:
    Y.append(tmp)

# print (X)
# print (Y)

x -= X[1]
X[1] = 0

x = abs(x)
y = abs(y)

total_X = sum(X)
total_Y = sum(Y)

lst_X = np.zeros(total_X + 1)
lst_X[0] = 1
for i in X:
    if i == 0:
        continue
    print (lst_X[i:])
    print (lst_X[:-i])
    lst_X[i:] = max(lst_X[i:], lst_X[:-i])

# print (lst_X)

lst_Y = np.zeros(total_Y + 1)
lst_Y[0] = 1
for i in Y:
    if i == 0:
        continue
    lst_Y[i:] = max(lst_Y[i:], lst_Y[:-i])

if x > total_X or y > total_Y:
    print ('No')
    exit()

if (total_X - x) % 2 == (total_Y - y) % 2 == 0 and int(lst_X[(total_X - x) // 2]) == 1 and int(lst_Y[(total_Y - y) // 2]) == 1:
    print ('Yes')
else:
    print ('No')

Submission status: Runtime Error

Solution code:
import numpy as np
s = list(input())
x, y = map(int, input().split())

X = [0]
Y = [0]

flag = True
tmp = 0
for i in s:
    if i == 'F':
        tmp += 1
    else:
        if flag:
            X.append(tmp)
        else:
            Y.append(tmp)
        tmp = 0
        flag = not flag

if flag:
    X.append(tmp)
else:
    Y.append(tmp)

# print (X)
# print (Y)

x -= X[1]
X[1] = 0

x = abs(x)
y = abs(y)

total_X = sum(X)
total_Y = sum(Y)

lst_X = np.zeros(total_X + 1)
lst_X[0] = 1
for i in X:
    if i == 0:
        continue
    print (lst_X[i:])
    print (lst_X[:-i])
    lst_X[i:] = max(lst_X[i:], lst_X[:-i])

print (lst_X)

lst_Y = np.zeros(total_Y + 1)
lst_Y[0] = 1
for i in Y:
    if i == 0:
        continue
    lst_Y[i:] = max(lst_Y[i:], lst_Y[:-i])

if x > total_X or y > total_Y:
    print ('No')
    exit()

if (total_X - x) % 2 == (total_Y - y) % 2 == 0 and int(lst_X[(total_X - x) // 2]) == 1 and int(lst_Y[(total_Y - y) // 2]) == 1:
    print ('Yes')
else:
    print ('No')

Submission status: Runtime Error

Solution code:
import numpy as np
s = list(input())
x, y = map(int, input().split())

X = [0]
Y = [0]

flag = True
tmp = 0
for i in s:
    if i == 'F':
        tmp += 1
    else:
        if flag:
            X.append(tmp)
        else:
            Y.append(tmp)
        tmp = 0
        flag = not flag

if flag:
    X.append(tmp)
else:
    Y.append(tmp)

# print (X)
# print (Y)

x -= X[1]
X[1] = 0

x = abs(x)
y = abs(y)

total_X = sum(X)
total_Y = sum(Y)

lst_X = np.zeros(total_X + 1)
lst_X[0] = 1
for i in X:
    if i == 0:
        continue
    lst_X[i:] = max(lst_X[i:], lst_X[:-i])

# print (lst_X)

lst_Y = [0] * (total_Y + 1)
lst_Y[0] = 1
for i in Y:
    if i == 0:
        continue
    for j in range(total_Y - i, -1, -1):
        if lst_Y[j] == 1:
            lst_Y[j + i] = 1

# print (lst_Y)
if x > total_X or y > total_Y:
    print ('No')
    exit()

if (total_X - x) % 2 == (total_Y - y) % 2 == 0 and lst_X[(total_X - x) // 2] == 1 and lst_Y[(total_Y - y) // 2]:
    print ('Yes')
else:
    print ('No')

Submission status: Runtime Error

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

x = abs(x)
y = abs(y)

X = [0]
Y = [0]

flag = True
tmp = 0
for i in s:
    if i == 'F':
        tmp += 1
    else:
        if flag:
            X.append(tmp)
        else:
            Y.append(tmp)
        tmp = 0
        flag = not flag

if flag:
    X.append(tmp)
else:
    Y.append(tmp)

# print (X)
# print (Y)

total_X = sum(X)
total_Y = sum(Y)

lst_X = [0] * (total_X + 1)
lst_X[0] = 1
for i in X:
    for j in range(total_X - i, -1, -1):
        if lst_X[j] == 1:
            lst_X[j + i] = 1

# print (lst_X)

lst_Y = [0] * (total_Y + 1)
lst_Y[0] = 1
for i in Y:
    for j in range(total_Y - i, -1, -1):
        if lst_Y[j] == 1:
            lst_Y[j + i] = 1

# print (lst_Y)

if (total_X - x) % 2 == (total_Y - y) % 2 == 0 and lst_X[(total_X - x) // 2] == 1 and lst_Y[(total_Y - y) // 2]:
    print ('Yes')
else:
    print ('No')

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

arr = list(map(len, s.split('T')))
EW = [arr[ew] for ew in range(0, len(arr), 2)]
NS = [arr[ns] for ns in range(1, len(arr), 2)]

# dp[i][j] := i回目までの移動で座標jにいることができるか
dp = [defaultdict(bool) for i in range(len(EW))]
dp[0][EW[0]] = True
for i in range(1, len(EW)):
    for prev in dp[i - 1].keys():
        dp[i][prev + EW[i]] = True
        dp[i][prev - EW[i]] = True
if not dp[-1][x]:
    print('No')
    exit(0)

dp = [defaultdict(bool) for i in range(len(NS))]
dp[0][NS[0]] = True
dp[0][-NS[0]] = True
for i in range(1, len(NS)):
    for prev in dp[i - 1].keys():
        dp[i][prev + NS[i]] = True
        dp[i][prev - NS[i]] = True
if not dp[-1][y]:
    print('No')
    exit(0)

print('Yes')

Submission status: Runtime Error

Solution code:
from collections import deque
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

S = str(input())
X, Y = LI()
N = len(S)
ans = "No"
Fx = deque()
Fy = deque()
ve = int(1)
cur = int(0)

for i in range(N):
    if S[i]=="F":
        cur +=1
    else:
        if ve==1:
            Fx.append(cur)
            cur = int(0)
            ve *= -1
        else:
            Fy.append(cur)
            cur = int(0)
            ve *= -1
if ve==1:
    Fx.append(cur)
    cur = int(0)
else:
    Fy.append(cur)
    cur = int(0)
xfirst = Fx.popleft()
X = X-xfirst

#print(Fx)
#print(Fy)
xlen = len(Fx)
ylen = len(Fy)
xneed = -1; yneed = -1
if (sum(Fx)-X)%2==0:
    xneed = (sum(Fx)-X)//2
if (sum(Fy)-Y)%2==0:
    yneed = (sum(Fy)-Y)//2
#print(xneed)
if xneed>0:
    dp = [[0] * (xneed + 1) for _ in range(xlen + 1)]
    dp[0][0] = 1
    for i in range(xlen):
        for j in range(max(xneed + 1 - Fx[i], 0)):
            if dp[i][j] != 0:
                dp[i + 1][j + Fx[i]] = dp[i][j]

#    print(dp)
#    print(dp[xlen][xneed])
if dp[xlen][xneed]==1 or xneed==0:
    if xneed > 0:
        dp = [[0] * (yneed + 1) for _ in range(ylen + 1)]
        dp[0][0] = 1
        for i in range(ylen):
            for j in range(max(yneed + 1 - Fy[i], 0)):
                if dp[i][j] != 0:
                    dp[i + 1][j + Fy[i]] = dp[i][j]

    if dp[ylen][yneed]==1 or yneed==0:
        ans = "Yes"


print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

s = str(input())
x,y = II()

N = len(s)
yoko = []
tate = []
ziku = True
count = 0

for i in range(N):
    if s[i]=='F':
        count += 1
    else:
        if ziku:
            yoko.append(count)
            ziku = False
        else:
            tate.append(count)
            ziku = True
        count = 0

if count!=0:
    if ziku:
        yoko.append(count)
    else:
        tate.append(count)

sum1 = sum(yoko)
sum2 = sum(tate)
if x>sum1 or y>sum2:
    print('No')
    exit()

yoko_yes = [False]*(2*sum1+1)
yoko_yes[sum1] = True

for yk in yoko:
    ok = []
    for i in range(2*sum1+1):
        if yoko_yes[i]:
            if 0<=i+yk<=2*sum1:
                ok.append(i+yk)
            if 0<=i-yk<=2*sum1:
                ok.append(i-yk)
    yoko_yes = [False]*(2*sum1+1)
    for o in ok:
        yoko_yes[o] = True

tate_yes = [False]*(2*sum2+1)
tate_yes[sum2] = True

for t in tate:
    ok = []
    for i in range(2*sum2+1):
        if tate_yes[i]:
            if 0<=i+t<=2*sum2:
                ok.append(i+t)
            if 0<=i-t<=2*sum2:
                ok.append(i-t)
    tate_yes = [False]*(2*sum2+1)
    for o in ok:
        tate_yes[o] = True

if yoko_yes[x+sum1] and tate_yes[y+sum2]:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

s = str(input())
x,y = II()

N = len(s)
yoko = []
tate = []
ziku = True
count = 0

for i in range(N):
    if s[i]=='F':
        count += 1
    else:
        if ziku:
            yoko.append(count)
            ziku = False
        else:
            tate.append(count)
            ziku = True
        count = 0

if count!=0:
    if ziku:
        yoko.append(count)
    else:
        tate.append(count)

sum1 = sum(yoko)
yoko_yes = [False]*(2*sum1+1)
yoko_yes[sum1] = True

for yk in yoko:
    ok = []
    for i in range(2*sum1+1):
        if yoko_yes[i]:
            if 0<=i+yk<=2*sum1:
                ok.append(i+yk)
            if 0<=i-yk<=2*sum1:
                ok.append(i-yk)
    yoko_yes = [False]*(2*sum1+1)
    for o in ok:
        yoko_yes[o] = True

sum2 = sum(tate)
tate_yes = [False]*(2*sum2+1)
tate_yes[sum2] = True

for t in tate:
    ok = []
    for i in range(2*sum2+1):
        if tate_yes[i]:
            if 0<=i+t<=2*sum2:
                ok.append(i+t)
            if 0<=i-t<=2*sum2:
                ok.append(i-t)
    tate_yes = [False]*(2*sum2+1)
    for o in ok:
        tate_yes[o] = True

if x>sum1 or y>sum2:
    print('No')
    exit()
    
if yoko_yes[x+sum1] and tate_yes[y+sum2]:
    print('Yes')
else:
    print('No')