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 sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

s=input()
x,y=map(int,input().split())
lst=[[],[]]
cnt=0
tmp=0
for i in range(len(s)):
    if s[i]=="F":
        tmp+=1
    else:
        if cnt==0:
            x-=tmp
        else:
            if tmp!=0:
                lst[cnt%2].append(tmp)
        tmp=0
        cnt+=1
if tmp!=0:
    lst[cnt%2].append(tmp)
dpx=[[0]*16001 for i in range(len(lst[0])+1)]
dpy=[[0]*16001 for i in range(len(lst[1])+1)]
dpx[0][8000]=1
dpy[0][8000]=1

for i in range(len(lst[0])):
    for j in range(16001):
        if dpx[i][j]!=0:
            dpx[i+1][j+lst[0][i]]+=1
            dpx[i+1][j-lst[0][i]]+=1

for i in range(len(lst[1])):
    for j in range(16001):
        if dpy[i][j]!=0:
            dpy[i+1][j+lst[1][i]]+=1
            dpy[i+1][j-lst[1][i]]+=1

if dpx[len(lst[0])][8000+x]!=0 and dpy[len(lst[0])][8000+y]!=0:
    print("Yes")
else:
    print("No")
# print(x,lst)

Submission status: Runtime Error

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

s=input()
x,y=map(int,input().split())
lst=[[],[]]
cnt=0
tmp=0
for i in range(len(s)):
    if s[i]=="F":
        tmp+=1
    else:
        if cnt==0:
            x-=tmp
        else:
            lst[cnt%2].append(tmp)
        tmp=0
        cnt+=1
if tmp!=0:
    lst[cnt%2].append(tmp)
dpx=[[0]*16001 for i in range(len(lst[0])+1)]
dpy=[[0]*16001 for i in range(len(lst[1])+1)]
dpx[0][8000]=1
dpy[0][8000]=1

for i in range(len(lst[0])):
    for j in range(16001):
        if dpx[i][j]!=0:
            dpx[i+1][j+lst[0][i]]+=1
            dpx[i+1][j-lst[0][i]]+=1

for i in range(len(lst[1])):
    for j in range(16001):
        if dpy[i][j]!=0:
            dpy[i+1][j+lst[1][i]]+=1
            dpy[i+1][j-lst[1][i]]+=1

if dpx[len(lst[0])][8000+x]!=0 and dpy[len(lst[0])][8000+y]!=0:
    print("Yes")
else:
    print("No")
# print(x,lst)

Submission status: Runtime Error

Solution code:
S = input()
X, Y = map(int, input().split())

A = [0]
for s in S:
    if s == 'T':
        A.append(0)
    else:
        A[-1] += 1

B = [n for n in A[1:: 2]]
X -= A[0]
A = [n for n in A[2:: 2]]

def canGo(nums, g):
    if not nums:
        return g == 0

    bias = sum(nums) + 10
    g += bias
    dp = (1 << bias)

    for n in nums:
        dp = (dp << n) | (dp >> n)
    return (dp & (1 << g)) > 0

if canGo(A, X) and canGo(B, Y):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
S = input()
X, Y = map(int, input().split())

A = [0]
for s in S:
    if s == 'T':
        A.append(0)
    else:
        A[-1] += 1

B = [n for n in A[1:: 2]]
X -= A[0]
A = [n for n in A[2:: 2]]

def canGo(nums, g):
    if not nums:
        return g == 0

    bias = sum(nums)
    g += bias
    dp = (1 << bias)

    for n in nums:
        dp = (dp << n) | (dp >> n)
    return (dp & (1 << g)) > 0

if canGo(A, X) and canGo(B, Y):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
S = input()
X, Y = map(int, input().split())

def run_length(s) -> list:
    res = [[s[0], 1]]
    for i in range(1, len(s)):
        if res[-1][0] == s[i]:
            res[-1][1] += 1
        else:
            res.append([s[i], 1])
    return res

RL = run_length(S)
if RL[0][0] == 'T':
    RL = [['F', 0]] + RL

SIZE = len(S)
nx = 1 << SIZE
ny = 1 << SIZE

x_flag = 1
for i in range(0, len(RL), 2):
    s, l = RL[i]
    if i == 0:
        nx = nx << l
    else:
        x_flag = (x_flag + RL[i - 1][1]) % 2
        if x_flag:
            nx = (nx << l) | (nx >> l)
        else:
            ny = (ny << l) | (ny >> l)

if ((nx >> (SIZE + X)) & 1) & ((ny >> (SIZE + Y)) & 1):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def foo(fe,x,ev):
    k = sum(fe)+1
    n = len(fe)
    d = [ [False]*(2*k+1) for i in range(n+1) ]
    d[0][k] = True
    if len(fe)>0:
        d[1][fe[0]+k] = True
        if not ev:
            d[1][-fe[0]+k] = True
    for i in range(1,n):
        for j in range(-k,k+1):
            if d[i][j+k]:
                d[i+1][j+fe[i]+k] = True
                d[i+1][j-fe[i]+k] = True
    return d[n][x+k]

s = ins()
x,y = inm()
f = [ [], [] ]
strk = 0
turn = 0
n = len(s)
for i in range(n):
    if s[i]=='T':
        f[turn].append(strk)
        turn = 1 - turn
        strk = 0
    else:
        strk += 1
f[turn].append(strk)
if foo(f[0],x,True) and foo(f[1],y,False):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

k = 8000
def foo(fe,x,ev):
    n = len(fe)
    d = [ [False]*(2*k+1) for i in range(n+1) ]
    d[0][k] = True
    d[1][fe[0]+k] = True
    if not ev:
        d[1][-fe[0]+k] = True
    for i in range(1,n):
        for j in range(-k,k+1):
            if d[i][j+k]:
                d[i+1][j+fe[i]+k] = True
                d[i+1][j-fe[i]+k] = True
    return d[n][x+k]

s = ins()
x,y = inm()
f = [ [], [] ]
strk = 0
turn = 0
n = len(s)
for i in range(n):
    if s[i]=='T':
        f[turn].append(strk)
        turn = 1 - turn
        strk = 0
    else:
        strk += 1
f[turn].append(strk)
if foo(f[0],x,True) and foo(f[1],y,False):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
order = list(map(len, input().split("T")))
x, y = map(int, input().split())
ans = "No"
longi = [order[i] for i in range(len(order)) if i % 2 == 0]
lati = [order[i] for i in range(len(order)) if i % 2 == 1]
def f(x, y, A, B, D):
  for p in A:
      if x > 0:
        x -= p
      else:
        x += p
  if x == 0:
    for q in B:
      if y > 0:
        y -= q
      else:
        y += q
    if y == 0:
      D = "Yes"
  return D
  
#print(longi, lati)
if sum(longi) >= abs(x):
  if sum(lati) >= abs(y):
    longi.sort(reverse=True)
    lati.sort(reverse=True)
    ans = f(x, y, longi, lati, ans)
    if ans == "No":
      x += x // abs(x) * abs(longi[-1])
      y += y // abs(y) * abs(lati[-1])
      ans = f(x, y, longi[:-1], lati[:-1], ans)
    
    
print(ans)

Submission status: Runtime Error

Solution code:
order = list(map(len, input().split("T")))
x, y = map(int, input().split())
ans = "No"
longi = [order[i] for i in range(len(order)) if i % 2 == 0]
lati = [order[i] for i in range(len(order)) if i % 2 == 1]
def f(x, y, A, B, D):
  for p in A:
      if x > 0:
        x -= p
      else:
        x += p
  if x == 0:
    for q in B:
      if y > 0:
        y -= q
      else:
        y += q
    if y == 0:
      D = "Yes"
  return D
  
print(longi, lati)
if sum(longi) >= abs(x):
  if sum(lati) >= abs(y):
    longi.sort(reverse=True)
    lati.sort(reverse=True)
    ans = f(x, y, longi, lati, ans)
    if ans == "No":
      x += x // abs(x) * abs(longi[-1])
      y += y // abs(y) * abs(lati[-1])
      ans = f(x, y, longi[:-2], lati[:-2], ans)
    
    
print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline


def check(arr, x):
    s = sum(arr)
    if (s+x) % 2 == 1:
        return False
    target = (s+x) // 2
    dp = [False] * (target+1)
    dp[0] = True
    for a in arr:
        for i in range(a, target+1):
            dp[i] = dp[i-a]
    return dp[-1]


s = input().rstrip() + 'T'
x, y = map(int, input().split())
X = []
Y = []
xy = 0
f_count = 0
for c in s:
    if c == 'T':
        if xy == 0:
            X.append(f_count)
        else:
            Y.append(f_count)
        f_count = 0
        xy = 1 - xy
    else:
        f_count += 1
x -= X[0]
X.pop(0)
if check(X, x) and check(Y, y):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def main():
    order_F = []
    order_F = input().rstrip().split('T')
    x, y = map(int, input().split())
    distance = [len(order_F[i]) for i in range(len(order_F))]
    dp_len = max(distance) + 1
    vert_DP = [False] * (dp_len + 1)
    side_DP = [False] * (dp_len + 1)
    vert_DP[0] = True
    side_DP[0] = True
    vert_sum = 0
    side_sum = 0
    x -= distance[0]
    for i in range(1, len(order_F)):
        if i % 2 == 0:
            side_sum += distance[i]
            for j in reversed(range(dp_len + 1 - distance[i])):
                if side_DP[j]:
                    side_DP[j + distance[i]] = True
        else:
            vert_sum += distance[i]
            for j in reversed(range(dp_len + 1 - distance[i])):
                if vert_DP[j]:
                    vert_DP[j + distance[i]] = True
    if side_sum < x or vert_sum < y:
        print("No")
    elif (side_sum - x) % 2 == 1 or (vert_sum - y) % 2 == 1:
        print("No")
    else:
        if side_DP[(side_sum - x)//2] and vert_DP[(vert_sum - y)//2]:
            print("Yes")
        else:
            print("No")

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def main():
    order_F = []
    order_F = input().rstrip().split('T')
    x, y = map(int, input().split())
    distance = [len(order_F[i]) for i in range(len(order_F))]
    dp_len = max(distance)
    vert_DP = [False] * (dp_len + 1)
    side_DP = [False] * (dp_len + 1)
    vert_DP[0] = True
    side_DP[0] = True
    vert_sum = 0
    side_sum = 0
    x -= distance[0]
    for i in range(1, len(order_F)):
        if i % 2 == 0:
            side_sum += distance[i]
            for j in reversed(range(dp_len + 1 - distance[i])):
                if side_DP[j]:
                    side_DP[j + distance[i]] = True
        else:
            vert_sum += distance[i]
            for j in reversed(range(dp_len + 1 - distance[i])):
                if vert_DP[j]:
                    vert_DP[j + distance[i]] = True
    if side_sum < x or vert_sum < y:
        print("No")
    elif (side_sum - x) % 2 == 1 or (vert_sum - y) % 2 == 1:
        print("No")
    else:
        if side_DP[(side_sum - x)//2] and vert_DP[(vert_sum - y)//2]:
            print("Yes")
        else:
            print("No")

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline
s = list(input())
x, y = map(int, input().split())
y = abs(y)
s.append('T')
x1 = []
y1 = []

count = 0
u = 0
for i in range(len(s)):
    if s[i] == 'F':
        count += 1
    else:
        if u % 2 == 0:
            x1.append(count)
            u += 1
            count = 0
        else:
            y1.append(count)
            u += 1
            count = 0

v = sum(x1)
w = sum(y1)
if v < x or w < y:
    print('No')
    exit()

dpx = [[0 for i in range(v + 1)] for j in range(len(x1) + 1)]
dpx[0][-1] = 1
x -= x1[0]
x1[0] = 0
v -= x1[0]
x = abs(x)

for i in range(len(x1)):
    for j in range(v + 1):
        if dpx[i][j] == 1:
            if j - 2 * x1[i] >= 0:
                dpx[i + 1][j - 2 * x1[i]] = 1
            dpx[i + 1][j] = 1

if len(y1) == 0:
    y1.append(0)
dpy = [[0 for i in range(w + 1)] for j in range(len(y1) + 1)]
dpy[0][-1] = 1

for i in range(len(y1)):
    for j in range(w + 1):
        if dpy[i][j] == 1:
            if j - 2 * y1[i] >= 0:
                dpy[i + 1][j - 2 * y1[i]] = 1
            dpy[i + 1][j] = 1

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

Submission status: Runtime Error

Solution code:
    import sys
    input = sys.stdin.readline
    s = list(input())
    x, y = map(int, input().split())
    y = abs(y)
    s.append('T')
    x1 = []
    y1 = []

    count = 0
    u = 0
    for i in range(len(s)):
        if s[i] == 'F':
            count += 1
        else:
            if u % 2 == 0:
                x1.append(count)
                u += 1
                count = 0
            else:
                y1.append(count)
                u += 1
                count = 0

    v = sum(x1)
    w = sum(y1)
    if v < x or w < y:
        print('No')
        exit()

    dpx = [[0 for i in range(v + 1)] for j in range(len(x1) + 1)]
    dpx[0][-1] = 1
    x -= x1[0]
    x1[0] = 0
    v-=x1[0]
    x=abs(x)

    for i in range(len(x1)):
        for j in range(v + 1):
            if dpx[i][j] == 1:
                if j - 2 * x1[i] >= 0:
                    dpx[i + 1][j - 2 * x1[i]] = 1
                dpx[i + 1][j] = 1

    if len(y1) == 0:
        y1.append(0)
    dpy = [[0 for i in range(w + 1)] for j in range(len(y1) + 1)]
    dpy[0][-1] = 1

    for i in range(len(y1)):
        for j in range(w + 1):
            if dpy[i][j] == 1:
                if j - 2 * y1[i] >= 0:
                    dpy[i + 1][j - 2 * y1[i]] = 1
                dpy[i + 1][j] = 1

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

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
s=list(input())
x,y = map(int, input().split())
x=abs(x)
y=abs(y)
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0

v=sum(x1)
w=sum(y1)

dpx=[[0 for i in range(v+1)] for j in range(len(x1)+1)]

dpx[0][-1]=1

for i in range(len(x1)):
    for j in range(v+1):
        if dpx[i][j]==1:
            if j-2*x1[i]>=0:
                dpx[i+1][j-2*x1[i]]=1
            dpx[i+1][j]=1

if len(y1)==0:
    y1.append(0)

dpy=[[0 for i in range(w+1)] for j in range(len(y1)+1)]
dpy[0][-1]=1

for i in range(len(y1)):
    for j in range(w+1):
        if dpy[i][j]==1:
            if j-2*y1[i]>=0:
                dpy[i+1][j-2*y1[i]]=1
            dpy[i+1][j]=1



if dpy[len(y1)][y]==1 and dpx[len(x1)][x]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
s=list(input())
x,y = map(int, input().split())
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0


dpx=[[0 for i in range(sum(x1)*2+2)] for j in range(len(x1)+1)]
if len(x1)<=2:
    dpx.append(0)
dpx[1][0]=1
for i in range(1,len(x1)):
    for j in range(-(sum(x1))-1,sum(x1)+1):
        if j-x1[i]<-sum(x1)-1:
            dpx[i + 1][j] =  dpx[i][j+x1[i]]
        elif j+x1[i]>=sum(x1)+1:
            dpx[i + 1][j] = dpx[i][j-x1[i]]
        else:
            dpx[i + 1][j] = dpx[i][j + x1[i]] or dpx[i][j - x1[i]]

dpy=[[0 for i in range(sum(y1)*2+2)] for j in range(len(y1)+1)]
if len(y1)==0:
    dpy.append(0)
dpy[0][0]=1

for i in range(len(y1)):
    for j in range(-sum(y1)-1,sum(y1)+1):
        if j-y1[i]<-sum(y1)-1:
            dpy[i + 1][j] = dpy[i][j + y1[i]]
        elif j+y1[i]>=sum(y1)+1:
            dpy[i + 1][j] = dpy[i][j - y1[i]]
        else:
            dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j+y1[i]]

if dpy[len(y1)][y]==1 and dpx[len(x1)][x-x1[0]]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
s=list(input())
x,y = map(int, input().split())
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0


dpx=[[0 for i in range(sum(x1)*2+2)] for j in range(len(x1)+1)]
if len(x1)<=2:
    dpx.append(0)
dpx[1][0]=1
for i in range(1,len(x1)):
    for j in range(-(sum(x1))-1,sum(x1)+1):
        if j-x1[i]>=-sum(x1)-1 and j+x1[i]<sum(x1)+1:
            dpx[i + 1][j] = dpx[i][j + x1[i]] or dpx[i][j-x1[i]] 
        elif j-x1[i]<-sum(x1)-1:
            dpx[i + 1][j] =  dpx[i][j+x1[i]] 
        elif j+x1[i]>=sum(x1)+1:
            dpx[i + 1][j] = dpx[i][j-x1[i]]






dpy=[[0 for i in range(sum(y1)*2+2)] for j in range(len(y1)+1)]
if len(y1)==0:
    dpy.append(0)
dpy[0][0]=1

for i in range(len(y1)):
    for j in range(-sum(y1)-1,sum(y1)+1):
        if j-y1[i]>=-sum(y1)-1 and j+y1[i]<sum(y1)+1:
            dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j+y1[i]] 
        elif j-y1[i]<-sum(y1)-1:
            dpy[i + 1][j] = dpy[i][j + y1[i]] 
        elif j+y1[i]>=sum(y1)+1:
            dpy[i + 1][j] = dpy[i][j - y1[i]]




if dpy[len(y1)][y]==1 and dpx[len(x1)][x-x1[0]]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
s=list(input())
x,y = map(int, input().split())
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0


dpx=[[0 for i in range(sum(x1)*2+2)] for j in range(len(x1)+1)]
if len(x1)<=2:
    dpx.append(0)
dpx[1][0]=1
for i in range(1,len(x1)):
    for j in range(-(sum(x1))-1,sum(x1)+1):
        if j-x1[i]>=-sum(x1)-1 and j+x1[i]<sum(x1)+1:
            dpx[i + 1][j] = dpx[i][j + x1[i]] or dpx[i][j-x1[i]] or dpx[i][j]
        elif j-x1[i]<-sum(x1)-1:
            dpx[i + 1][j] =  dpx[i][j+x1[i]] or dpx[i][j]
        elif j+x1[i]>=sum(x1)+1:
            dpx[i + 1][j] = dpx[i][j-x1[i]] or dpx[i][j]
        else:
            dpx[i + 1][j] = dpx[i][j]





dpy=[[0 for i in range(sum(y1)*2+2)] for j in range(len(y1)+1)]
if len(y1)==0:
    dpy.append(0)
dpy[0][0]=1

for i in range(len(y1)):
    for j in range(-sum(y1)-1,sum(y1)+1):
        if j-y1[i]>=-sum(y1)-1 and j+y1[i]<sum(y1)+1:
            dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j+y1[i]] or dpy[i][j]
        elif j-y1[i]<-sum(y1)-1:
            dpy[i + 1][j] = dpy[i][j + y1[i]] or dpy[i][j]
        elif j+y1[i]>=sum(y1)+1:
            dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j]
        else:
            dpy[i + 1][j] =  dpy[i][j]




if dpy[len(y1)][y]==1 and dpx[len(x1)][x-x1[0]]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s=list(input())
x,y = map(int, input().split())
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0


dpx=[[0 for i in range(sum(x1)*2+2)] for j in range(len(x1)+1)]
if len(x1)<=2:
    dpx.append(0)
dpx[1][0]=1
for i in range(1,len(x1)):
    for j in range(-(sum(x1))-1,sum(x1)+1):
        if j-x1[i]>=-sum(x1)-1 and j+x1[i]<sum(x1)+1:
            dpx[i + 1][j] = dpx[i][j + x1[i]] or dpx[i][j-x1[i]] or dpx[i][j]
        elif j-x1[i]<-sum(x1)-1:
            dpx[i + 1][j] =  dpx[i][j+x1[i]] or dpx[i][j]
        elif j+x1[i]>=sum(x1)+1:
            dpx[i + 1][j] = dpx[i][j-x1[i]] or dpx[i][j]
        else:
            dpx[i + 1][j] = dpx[i][j]





dpy=[[0 for i in range(sum(y1)*2+2)] for j in range(len(y1)+1)]
if len(y1)==0:
    dpy.append(0)
dpy[0][0]=1

for i in range(len(y1)):
    for j in range(-sum(y1)-1,sum(y1)+1):
        if j-y1[i]>=-sum(y1)-1 and j+y1[i]<sum(y1)+1:
            dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j+y1[i]] or dpy[i][j]
        elif j-y1[i]<-sum(y1)-1:
            dpy[i + 1][j] = dpy[i][j + y1[i]] or dpy[i][j]
        elif j+y1[i]>=sum(y1)+1:
            dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j]
        else:
            dpy[i + 1][j] =  dpy[i][j]




if dpy[len(y1)][y]==1 and dpx[len(x1)][x-x1[0]]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s=list(input())
x,y = map(int, input().split())
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0


dpx=[[0 for i in range(sum(x1)*2+2)] for j in range(len(x1)+1)]
if len(x1)<=2:
    dpx.append(0)
dpx[1][0]=1
for i in range(1,len(x1)):
    for j in range(-(sum(x1))-1,sum(x1)+1):
        dpx[i + 1][j] = dpx[i][j - x1[i]] or dpx[i][j+x1[i]]

dpy=[[0 for i in range(sum(y1)*2+2)] for j in range(len(y1)+1)]
if len(y1)==0:
    dpy.append(0)
dpy[0][0]=1

for i in range(len(y1)):
    for j in range(-sum(y1)-1,sum(y1)+1):
        dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j+y1[i]]


if dpy[len(y1)][y]==1 and dpx[len(x1)][x-x1[0]]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s=list(input())
x,y = map(int, input().split())
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0

if (len(x1)<=1 and x1[0]!=x) or (len(y1)==0 and y1[0]!=y):
    print('No')
    exit()

if (len(x1)==1 and x1[0]==x) and (len(y1)==0 and y1[0]==y):
    print('Yes')
    exit()



dpx=[[0 for i in range(sum(x1)*2+2)] for j in range(len(x1)+1)]
if len(x1)>=2:
    dpx[1][0]=1
for i in range(1,len(x1)):
    for j in range(-(sum(x1))-1,sum(x1)+1):
        dpx[i + 1][j] = dpx[i][j - x1[i]] or dpx[i][j+x1[i]]

dpy=[[0 for i in range(sum(y1)*2+2)] for j in range(len(y1)+1)]

dpy[0][0]=1

for i in range(len(y1)):
    for j in range(-sum(y1)-1,sum(y1)+1):
        dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j+y1[i]]


if dpy[len(y1)][y]==1 and dpx[len(x1)][x-x1[0]]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s=list(input())
x,y = map(int, input().split())
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0

if (len(x1)<=1 and x1[0]!=x) or (len(y1)==0 and y1[0]!=y):
    print('No')
    exit()

dpx=[[0 for i in range(sum(x1)*2+2)] for j in range(len(x1)+1)]
if len(x1)>=2:
    dpx[1][0]=1
for i in range(1,len(x1)):
    for j in range(-(sum(x1))-1,sum(x1)+1):
        dpx[i + 1][j] = dpx[i][j - x1[i]] or dpx[i][j+x1[i]]

dpy=[[0 for i in range(sum(y1)*2+2)] for j in range(len(y1)+1)]

dpy[0][0]=1

for i in range(len(y1)):
    for j in range(-sum(y1)-1,sum(y1)+1):
        dpy[i + 1][j] = dpy[i][j - y1[i]] or dpy[i][j+y1[i]]


if dpy[len(y1)][y]==1 and dpx[len(x1)][x-x1[0]]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
S=input()
x,y=map(int,input().split())
import itertools
Xmove=[]
Ymove=[]
Xbase=0
Ybase=0
Xtar=True
for key,g in itertools.groupby(S):
  num=len(list(g))
  if key=="T":
    if num%2==1:
      Xtar^=True
  else:
    if Xtar:
      Xmove.append(num)
      Xbase+=num
    else:
      Ymove.append(num)
      Ybase+=num
if Xbase<x or Ybase<y:
  print("No")
  exit(0)

dpX=[[False for i in range(Xbase*2+1)] for j in range(2)]
dpY=[[False for i in range(Ybase*2+1)] for j in range(2)]
Xind=0

if S[0]=="F":
  dpX[0][Xbase+Xmove[0]]=True
  Xind=1
else:
  dpX[0][Xbase]=True
dpY[0][Ybase]=True

cur=0
for i in range(Xind,len(Xmove)):
  for j in range(len(dpX[cur])):
    if dpX[cur][j]:
      dpX[1-cur][j+Xmove[i]]=True
      dpX[1-cur][j-Xmove[i]]=True
      dpX[cur][j]=False
  cur=1-cur
  
if not dpX[cur][x+Xbase]:
  print("No")
  exit(0)
  
cur=0
for i in range(len(Ymove)):
  for j in range(len(dpY[cur])):
    if dpY[cur][j]:
      dpY[1-cur][j+Ymove[i]]=True
      dpY[1-cur][j-Ymove[i]]=True
      dpY[cur][j]=False
  cur=1-cur
  
if dpY[cur][y+Ybase]:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
S=input()
x,y=map(int,input().split())
import itertools
Xmove=[]
Ymove=[]
Xbase=0
Ybase=0
Xtar=True
for key,g in itertools.groupby(S):
  num=len(list(g))
  if key=="T":
    if num%2==1:
      Xtar^=True
  else:
    if Xtar:
      Xmove.append(num)
      Xbase+=num
    else:
      Ymove.append(num)
      Ybase+=num
if Xbase<x or Ybase<y:
  print("No")
  exit(0)

dpX=[[False for i in range(Xbase*2+1)] for j in range(2)]
dpY=[[False for i in range(Ybase*2+1)] for j in range(2)]
Xind=0

if S[0]=="F":
  dpX[0][Xbase+Xmove[0]]=True
  Xind=1
else:
  dpx[0][Xbase]=True
dpY[0][Ybase]=True

cur=0
for i in range(Xind,len(Xmove)):
  for j in range(len(dpX[cur])):
    if dpX[cur][j]:
      dpX[1-cur][j+Xmove[i]]=True
      dpX[1-cur][j-Xmove[i]]=True
      dpX[cur][j]=False
  cur=1-cur
  
if not dpX[cur][x+Xbase]:
  print("No")
  exit(0)
  
cur=0
for i in range(len(Ymove)):
  for j in range(len(dpY[cur])):
    if dpY[cur][j]:
      dpY[1-cur][j+Ymove[i]]=True
      dpY[1-cur][j-Ymove[i]]=True
      dpY[cur][j]=False
  cur=1-cur
  
if dpY[cur][y+Ybase]:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
s = input().strip()
x,y = map(int,input().split())
C = {}
cur = 0
cnt = 0
for i in range(len(s)):
    if s[i]=="F":
        cnt += 1
    else:
        C[cur] = cnt
        cur += 1
        cnt = 0
C[cur] = cnt
AX = []
AY = []
for a in C:
    if a>0 and a%2==0 and C[a]>0:
        AX.append(C[a])
    elif a%2==1 and C[a]>0:
        AY.append(C[a])
cntx = sum(AX)
dpx = [[0 for _ in range(2*cntx+1)] for _ in range(len(AX)+1)]
dpx[0][cntx] = 1
if cntx>0:
    dpx[1][cntx-AX[0]] = 1
    dpx[1][cntx+AX[0]] = 1
    for i in range(2,len(AX)+1):
        for j in range(2*cntx+1):
            if j-AX[i-1]>=0:
                dpx[i][j] = dpx[i-1][j-AX[i-1]+cntx]
                if j+AX[i-1]<=cntx:
                    dpx[i][j] = max(dpx[i][j],dpx[i-1][j+AX[i-1]+cntx])
            elif j+AX[i-1]<=cntx:
                dpx[i][j] = dpx[i-1][j+AX[i-1]+cntx]
cnty = sum(AY)
dpy = [[0 for _ in range(2*cnty+1)] for _ in range(len(AY)+1)]
dpy[0][cnty] = 1
if cnty>0:
    dpy[1][cnty-AY[0]] = 1
    dpy[1][cnty+AY[0]] = 1
    for i in range(2,len(AY)+1):
        for j in range(2*cnty+1):
            if j-AY[i-1]>=0:
                dpy[i][j] = dpy[i-1][j-AY[i-1]+cnty]
                if j+AY[i-1]<=cnty:
                    dpy[i][j] = max(dpy[i][j],dpy[i-1][j+AY[i-1]+cnty])
            elif j+AY[i-1]<=cnty:
                dpy[i][j] = dpy[i-1][j+AY[i-1]+cnty]
if C[0]-cntx<=x<=C[0]+cntx and dpx[len(AX)][x-C[0]+cntx]==1 and -cnty<=y<=cnty and dpy[len(AY)][y+cnty]==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = input().strip()
x,y = map(int,input().split())
C = {}
cur = 0
cnt = 0
for i in range(len(s)):
    if s[i]=="F":
        cnt += 1
    else:
        C[cur] = cnt
        cur += 1
        cnt = 0
C[cur] = cnt
AX = []
AY = []
for a in C:
    if a>0 and a%2==0 and C[a]>0:
        AX.append(C[a])
    elif a%2==1 and C[a]>0:
        AY.append(C[a])
cntx = sum(AX)
dpx = [[0 for _ in range(2*cntx+1)] for _ in range(len(AX)+1)]
dpx[0][cntx] = 1
if cntx>0:
    dpx[1][cntx-AX[0]] = 1
    dpx[1][cntx+AX[0]] = 1
    for i in range(2,len(AX)+1):
        for j in range(2*cntx+1):
            dpx[i][j] = dpx[i-1][j-AX[i-1]+cntx]
            if j+AX[i-1]<=cntx:
                dpx[i][j] = max(dpx[i][j],dpx[i-1][j+AX[i-1]+cntx])
cnty = sum(AY)
dpy = [[0 for _ in range(2*cnty+1)] for _ in range(len(AY)+1)]
dpy[0][cnty] = 1
if cnty>0:
    dpy[1][cnty-AY[0]] = 1
    dpy[1][cnty+AY[0]] = 1
    for i in range(2,len(AY)+1):
        for j in range(2*cnty+1):
            dpy[i][j] = dpy[i-1][j-AY[i-1]+cnty]
            if j+AY[i-1]<=cnty:
                dpy[i][j] = max(dpy[i][j],dpy[i-1][j+AY[i-1]+cnty])
if C[0]-cntx<=x<=C[0]+cntx and dpx[len(AX)][x-C[0]+cntx]==1 and -cnty<=y<=cnty and dpy[len(AY)][y+cnty]==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
S=input()
x,y=map(int,input().split())
Xmove=[]
Ymove=[]
xdist=True
cnt=0
for i in range(len(S)):
  if S[i]=="T":
    if xdist:
      Xmove.append(cnt)
    else:
      Ymove.append(cnt)
    cnt=0
    xdist^=True
  else:
    cnt+=1
if S[-1]=="F":
  if xdist:
    Xmove.append(cnt)
  else:
    Ymove.append(cnt)

Xbase=sum(Xmove)
Ybase=sum(Ymove)
dpX=[[False for j in range(max(Xbase,x)*2+1)] for i in range(2)]
dpY=[[False for j in range(max(Ybase,y)*2+1)] for i in range(2)]

indX=0
ind=0
if S[0]=="F":
  dpX[ind][Xbase+Xmove[0]]=True
  indX=1
else:
  dpX[ind][Xbase]=True
dpY[ind][Ybase]=True

if Xbase==0:
  if x!=0:
    print("No")
    exit(0)
else:
  for i in range(indX,len(Xmove)):
    for j in range(len(dpX[ind])):
      if dpX[ind][j]:
        dpX[1-ind][j+Xmove[i]]=True
        dpX[1-ind][j-Xmove[i]]=True
    dpX[ind]=[False for _ in range(Xbase*2+1)]
    ind=1-ind

if not dpX[ind][Xbase+x]:
  print("No")
  exit(0)
  
if Ybase==0:
  if y!=0:
    print("No")
    exit(0)
else:
  ind=0
  for i in range(len(Ymove)):
    for j in range(len(dpY[ind])):
      if dpY[ind][j]:
        dpY[1-ind][j+Ymove[i]]=True
        dpY[1-ind][j-Ymove[i]]=True
    dpY[ind]=[False for _ in range(Ybase*2+1)]
    ind=1-ind
    
print(("No","Yes")[dpY[ind][Ybase+y]])