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()
x,y = map(int,input().split())
k = 0
data = [[],[]]
f = 0
p = 1
for s_ in s:
    if p==1 and s_=='F':
        x -= 1
        continue
    p = 0
    if s_ == 'T':
        if f:
            data[k].append(f)
        k = (k+1)%2
        f = 0
    else:
        f += 1
if f:
    data[k].append(f)

nx = sum(data[0])
ny = sum(data[1])

if nx<x or ny<y:
    print('No')
    exit()

dpx = [[0]*8001 for _ in range(len(data[0])+1)]
dpy = [[0]*8001 for _ in range(len(data[1])+1)]
x_zero = 0
y_zero = 0
dpx[0][x_zero] = 1
dpy[0][y_zero] = 1

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

for i in range(len(data[1])):
    for j in range(len(dpy[i])):
        if dpy[i][j]==1:
            dpy[i+1][j+data[1][i]] += 1
            dpy[i+1][j-data[1][i]] += 1
if dpx[-1][x_zero+x]>=1 and dpy[-1][y_zero+y]>=1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
k = 0
data = [[],[]]
f = 0
p = 1
for s_ in s:
    if p==1 and s_=='F':
        x -= 1
        continue
    p = 0
    if s_ == 'T':
        if f:
            data[k].append(f)
        k = (k+1)%2
        f = 0
    else:
        f += 1
if f:
    data[k].append(f)

nx = sum(data[0])
ny = sum(data[1])

if nx<x or ny<y:
    print('No')
    exit()

dpx = [[0]*8001 for _ in range(len(data[0])+1)]
dpy = [[0]*8001 for _ in range(len(data[1])+1)]
x_zero = 4000
y_zero = 4000
dpx[0][x_zero] = 1
dpy[0][y_zero] = 1

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

for i in range(len(data[1])):
    for j in range(len(dpy[i])):
        if dpy[i][j]==1:
            dpy[i+1][j+data[1][i]] = 1
            dpy[i+1][j-data[1][i]] = 1
if dpx[-1][x_zero+x]==1 and dpy[-1][y_zero+y]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
k = 0
data = [[],[]]
f = 0
p = 1
for s_ in s:
    if p==1 and s_=='F':
        x -= 1
        continue
    p = 0
    if s_ == 'T':
        if f:
            data[k].append(f)
        k = (k+1)%2
        f = 0
    else:
        f += 1
if f:
    data[k].append(f)

nx = sum(data[0])
ny = sum(data[1])

if nx<x or ny<y:
    print('No')
    exit()

dpx = [[0]*8001 for _ in range(len(data[0])+1)]
dpy = [[0]*8001 for _ in range(len(data[1])+1)]
x_zero = 0
y_zero = 0
dpx[0][x_zero] = 1
dpy[0][y_zero] = 1

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

for i in range(len(data[1])):
    for j in range(len(dpy[i])):
        if dpy[i][j]==1:
            dpy[i+1][j+data[1][i]] = 1
            dpy[i+1][j-data[1][i]] = 1
if dpx[-1][x_zero+x]==1 and dpy[-1][y_zero+y]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
k = 0
data = [[],[]]
f = 0
p = 1
for s_ in s:
    if p==1 and s_=='F':
        x -= 1
        continue
    p = 0
    if s_ == 'T':
        if f:
            data[k].append(f)
        k = (k+1)%2
        f = 0
    else:
        f += 1
if f:
    data[k].append(f)

nx = sum(data[0])
ny = sum(data[1])

if nx<x or ny<y:
    print('No')
    exit()

dpx = [[0]*((nx+10)*2) for _ in range(len(data[0])+1)]
dpy = [[0]*((ny+10)*2) for _ in range(len(data[1])+1)]
x_zero = 0
y_zero = 0
dpx[0][x_zero] = 1
dpy[0][y_zero] = 1

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

for i in range(len(data[1])):
    for j in range(len(dpy[i])):
        if dpy[i][j]==1:
            dpy[i+1][j+data[1][i]] = 1
            dpy[i+1][j-data[1][i]] = 1
if dpx[-1][x_zero+x]==1 and dpy[-1][y_zero+y]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
k = 0
data = [[],[]]
f = 0
p = 1
for s_ in s:
    if p==1 and s_=='F':
        x -= 1
        continue
    p = 0
    if s_ == 'T':
        if f:
            data[k].append(f)
        k = (k+1)%2
        f = 0
    else:
        f += 1
if f:
    data[k].append(f)

nx = sum(data[0])
ny = sum(data[1])

if nx<x or ny<y:
    print('No')
    exit()

dpx = [[0]*((nx+10)*2) for _ in range(len(data[0])+1)]
dpy = [[0]*((ny+10)*2) for _ in range(len(data[1])+1)]
x_zero = nx+5
y_zero = ny+5
dpx[0][x_zero] = 1
dpy[0][y_zero] = 1

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

for i in range(len(data[1])):
    for j in range(len(dpy[i])):
        if dpy[i][j]==1:
            dpy[i+1][j+data[1][i]] = 1
            dpy[i+1][j-data[1][i]] = 1
if dpx[-1][x_zero+x]==1 and dpy[-1][y_zero+y]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
k = 0
data = [[],[]]
f = 0
p = 1
for s_ in s:
    if p==1 and s_=='F':
        x -= 1
        continue
    p = 0
    if s_ == 'T':
        if f:
            data[k].append(f)
        k = (k+1)%2
        f = 0
    else:
        f += 1
if f:
    data[k].append(f)

nx = sum(data[0])
ny = sum(data[1])

if nx<x or ny<y:
    print('No')
    exit()

dpx = [[0]*((nx+10)//2) for _ in range(len(data[0])+1)]
dpy = [[0]*((ny+10)//2) for _ in range(len(data[1])+1)]
x_zero = nx+5
y_zero = ny+5
dpx[0][x_zero] = 1
dpy[0][y_zero] = 1

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

for i in range(len(data[1])):
    for j in range(len(dpy[i])):
        if dpy[i][j]==1:
            dpy[i+1][j+data[1][i]] = 1
            dpy[i+1][j-data[1][i]] = 1
if dpx[-1][x_zero+x]==1 and dpy[-1][y_zero+y]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
k = 0
data = [[],[]]
f = 0
p = 1
for s_ in s:
    if p==1 and s_=='F':
        x -= 1
        continue
    p = 0
    if s_ == 'T':
        if f:
            data[k].append(f)
        k = (k+1)%2
        f = 0
    else:
        f += 1
if f:
    data[k].append(f)

nx = sum(data[0])
ny = sum(data[1])

if nx<x or ny<y:
    print('No')
    exit()

dpx = [[0]*(nx+2)*2 for _ in range(len(data[0])+1)]
dpy = [[0]*(ny+2)*2 for _ in range(len(data[1])+1)]
x_zero = nx+1
y_zero = ny+1
dpx[0][x_zero] = 1
dpy[0][y_zero] = 1

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

for i in range(len(data[1])):
    for j in range(len(dpy[i])):
        if dpy[i][j]==1:
            dpy[i+1][j+data[1][i]] = 1
            dpy[i+1][j-data[1][i]] = 1
if dpx[-1][x_zero+x]==1 and dpy[-1][y_zero+y]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
k = 0
data = [[],[]]
f = 0
p = 1
for s_ in s:
    if p==1 and s_=='F':
        x -= 1
        continue
    p = 0
    if s_ == 'T':
        if f:
            data[k].append(f)
        k = (k+1)%2
        f = 0
    else:
        f += 1
if f:
    data[k].append(f)

nx = sum(data[0])
ny = sum(data[1])

dpx = [[0]*max((nx+2)*2,(x+2)*2) for _ in range(len(data[0])+1)]
dpy = [[0]*max((ny+2)*2,(y+2)*2) for _ in range(len(data[1])+1)]
x_zero = max(nx+1,x+1)
y_zero = max(ny+1,y+1)
dpx[0][x_zero] = 1
dpy[0][y_zero] = 1

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

for i in range(len(data[1])):
    for j in range(len(dpy[i])):
        if dpy[i][j]==1:
            dpy[i+1][j+data[1][i]] = 1
            dpy[i+1][j-data[1][i]] = 1
if dpx[-1][x_zero+x]==1 and dpy[-1][y_zero+y]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
k = 0
data = [[],[]]
f = 0
p = 1
for s_ in s:
    if p==1 and s_=='F':
        x -= 1
        continue
    p = 0
    if s_ == 'T':
        if f:
            data[k].append(f)
        k = (k+1)%2
        f = 0
    else:
        f += 1
if f:
    data[k].append(f)

nx = sum(data[0])
ny = sum(data[1])

dpx = [[0]*max((nx+2)*2,(x+1)*2) for _ in range(len(data[0])+1)]
dpy = [[0]*max((ny+2)*2,(y+1)*2) for _ in range(len(data[1])+1)]
dpx[0][(nx+1)//2] = 1
dpy[0][(ny+1)//2] = 1

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

for i in range(len(data[1])):
    for j in range(len(dpy[i])):
        if dpy[i][j]==1:
            dpy[i+1][j+data[1][i]] = 1
            dpy[i+1][j-data[1][i]] = 1
if dpx[-1][(nx+1)//2+x]==1 and dpy[-1][(ny+1)//2+y]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
k = 0
data = [[],[]]
f = 0
p = 1
for s_ in s:
    if p==1 and s_=='F':
        x -= 1
        continue
    p = 0
    if s_ == 'T':
        if f:
            data[k].append(f)
        k = (k+1)%2
        f = 0
    else:
        f += 1
if f:
    data[k].append(f)

nx = sum(data[0])
ny = sum(data[1])

dpx = [[0]*(nx*2) for _ in range(len(data[0])+1)]
dpy = [[0]*(ny*2) for _ in range(len(data[1])+1)]
dpx[0][(nx+1)//2] = 1
dpy[0][(ny+1)//2] = 1

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

for i in range(len(data[1])):
    for j in range(len(dpy[i])):
        if dpy[i][j]==1:
            dpy[i+1][j+data[1][i]] = 1
            dpy[i+1][j-data[1][i]] = 1
if dpx[-1][(nx+1)//2+x]==1 and dpy[-1][(ny+1)//2+y]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
k = 0
data = [[],[]]
f = 0
p = 1
for s_ in s:
    if p==1 and s_=='F':
        x -= 1
        continue
    p = 0
    if s_ == 'T':
        if f:
            data[k].append(f)
        k = (k+1)%2
        f = 0
    else:
        f += 1
if f:
    data[k].append(f)

nx = sum(data[0])
ny = sum(data[1])

dpx = [[0]*(nx+2) for _ in range(len(data[0])+1)]
dpy = [[0]*(ny+2) for _ in range(len(data[1])+1)]
dpx[0][(nx+1)//2] = 1
dpy[0][(ny+1)//2] = 1

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

for i in range(len(data[1])):
    for j in range(len(dpy[i])):
        if dpy[i][j]==1:
            dpy[i+1][j+data[1][i]] = 1
            dpy[i+1][j-data[1][i]] = 1
if dpx[-1][(nx+1)//2+x]==1 and dpy[-1][(ny+1)//2+y]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
k = 0
data = [[],[]]
f = 0
p = 1
for s_ in s:
    if p==1 and s_=='F':
        x -= 1
        continue
    p = 0
    if s_ == 'T':
        if f:
            data[k].append(f)
        k = (k+1)%2
        f = 0
    else:
        f += 1
if f:
    data[k].append(f)
def dfs(d,l, pos, ind):
    if ind==len(l):
        if d==pos:
            return 1
        else:
            return 0
    ret1 = dfs(d, l, pos+l[ind], ind+1)
    ret2 = dfs(d, l, pos-l[ind], ind+1)
    if ret1+ret2>0:
        return 1
    else:
        return 0

if dfs(x,data[0],0,0) and dfs(y,data[1],0,0):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    x,y = f()

    flag = 1
    cnt = 0
    xa = []
    ya = []
    s += 'T'
    for i in s:
        if i == 'T':
            if flag == 1:
                if cnt:
                    xa.append(cnt)
            else:
                if cnt:
                    ya.append(cnt)
            cnt = 0
            flag = flag^1
        else:
            cnt += 1
            
        

    xvis = [0] * 8000
    xvis[0] = 1
    for i in xa:
        for j in range(8000, 0, -1):
            if j-i>=0 and xvis[j-i]:
                xvis[j] = 1
    
    yvis = [0] * 8000
    yvis[0] = 1
    for i in ya:
        for j in range(8000, 0, -1):
            if j-i>=0 and yvis[j-i]:
                yvis[j] = 1
    

    if xvis[x] and yvis[y]:
        print('Yes')
    else:
        print('No')


solve()

Submission status: Runtime Error

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

X=[]
Y=[]

M=[]
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        M.append(i)
print(M)
M+=[0]

if s[0]=='F':
    ans_x=M[0]+1
    ans_y=0
    for i in range(1,len(M)-1,2):
        if M[i]%2==0:
            ans_x+=M[i+1]-M[i]
        else:
            ans_y+=M[i+1]-M[i]
else:
    if 
    for i in range(0,len(M-1),2):
        if M[i]%2==0:
            ans_x+=M[i+1]-M[i]
        else:
            ans_y+=M[i+1]-M[i]

Submission status: Runtime Error

Solution code:
import unittest
import abc082d as tester

def ioByFile(fn='inputFile.txt'):
	with open(fn) as f:
		for line in f:
			yield line

def getCorrect(fn='correct.txt'):
	with open(fn) as f:
		return f.read()

class InputTests(unittest.TestCase):
	def _calFUT(self, io):
		return str(tester.main(io))+'\n'
		
	def test_it(self):
		testInput=ioByFile()
		io=lambda : next(testInput)
		actual = self._calFUT(io)
		
		self.assertEqual(actual,getCorrect())

if __name__ == "__main__":
	unittest.main()

Submission status: Runtime Error

Solution code:
s = input()
x, y = [int(item) for item in input().split()]
if abs(x) > 8000 or abs(y) > 8000:
    print("No")
    exit()

rl = []
ud = []
state_is_rl = True 
length = 0
for c in s:
    if c == "T":
        if state_is_rl:
            if length > 0:
                rl.append(length)
            state_is_rl = False 
        else:
            if length > 0:
                ud.append(length)
            state_is_rl = True
        length = 0
    if c == "F":
        length += 1
if state_is_rl:
    rl.append(length)
else:
    ud.append(length)

memo_rl = [1] + [0] * 8799
memo_ud = [1] + [0] * 8799
zeros = [0] * 8800
tmp = [0] * 8800
sum_val = 0
for i, item in enumerate(rl):
    sum_val += item
    tmp = zeros[:]
    if i == 0:
        if x <= rl[0]:
            x = abs(rl[0] - x)
        else:
            x = x - rl[0]
        memo_rl[0] = 1
    else:
        for j in range(sum_val+1):
            if memo_rl[j] == 1:
                if j - item >= 0:
                    tmp[j - item] = 1
                tmp[j + item] = 1
        memo_rl = tmp[:]

y = abs(y)
for i, item in enumerate(ud):
    sum_val += item
    tmp = zeros[:]
    for j in range(sum_val+1):
        if memo_ud[j] == 1:
            if j - item >= 0:
                tmp[j - item] = 1
            tmp[j + item] = 1
    memo_ud = tmp[:]

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

Submission status: Runtime Error

Solution code:
s = input()
x, y = [int(item) for item in input().split()]
if abs(x) > 8000 or abs(y) > 8000:
    print("No")
    exit()

rl = []
ud = []
state_is_rl = True 
length = 0
for c in s:
    if c == "T":
        if state_is_rl:
            if length > 0:
                rl.append(length)
            state_is_rl = False 
        else:
            if length > 0:
                ud.append(length)
            state_is_rl = True
        length = 0
    if c == "F":
        length += 1
if state_is_rl:
    rl.append(length)
else:
    ud.append(length)

memo_rl = [1] + [0] * 8001
memo_ud = [1] + [0] * 8001
zeros = [0] * 8001
tmp = [0] * 8001
sum_val = 0
for i, item in enumerate(rl):
    sum_val += item
    tmp = zeros[:]
    if i == 0:
        if x <= rl[0]:
            x = abs(rl[0] - x)
        else:
            x = x - rl[0]
        memo_rl[0] = 1
    else:
        for j in range(sum_val+1):
            if memo_rl[j] == 1:
                if j - item >= 0:
                    tmp[j - item] = 1
                tmp[j + item] = 1
        memo_rl = tmp[:]

y = abs(y)
for i, item in enumerate(ud):
    sum_val += item
    tmp = zeros[:]
    for j in range(sum_val+1):
        if memo_ud[j] == 1:
            if j - item >= 0:
                tmp[j - item] = 1
            tmp[j + item] = 1
    memo_ud = tmp[:]

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

Submission status: Runtime Error

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

rl = []
ud = []
state_is_rl = True 
length = 0
for c in s:
    if c == "T":
        if state_is_rl:
            if length > 0:
                rl.append(length)
            state_is_rl = False 
        else:
            if length > 0:
                ud.append(length)
            state_is_rl = True
        length = 0
    if c == "F":
        length += 1
if state_is_rl:
    rl.append(length)
    rl.append(0)
else:
    ud.append(length)
    ud.append(0)

memo_rl = [0] * 8001
memo_ud = [0] * 8001
zeros = [0] * 8001
tmp = [0] * 8001
sum_val = 0
for i, item in enumerate(rl):
    sum_val += item
    tmp = zeros[:]
    if i == 0:
        if x <= rl[0]:
            x = abs(rl[0] - x)
        else:
            x = x - rl[0]
        memo_rl[0] = 1
    else:
        for j in range(sum_val+1):
            if memo_rl[j] == 1:
                if j - item >= 0:
                    tmp[j - item] = 1
                tmp[j + item] = 1
        memo_rl = tmp[:]

y = abs(y)
memo_ud[0] = 1
for i, item in enumerate(ud):
    sum_val += item
    tmp = zeros[:]
    for j in range(sum_val+1):
        if memo_ud[j] == 1:
            if j - item >= 0:
                tmp[j - item] = 1
            tmp[j + item] = 1
    memo_ud = tmp[:]

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

Submission status: Runtime Error

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

rl = []
ud = []
state_is_rl = True 
length = 0
for c in s:
    if c == "T":
        if state_is_rl and length > 0:
            rl.append(length)
            state_is_rl = False 
        elif length > 0:
            ud.append(length)
            state_is_rl = True
        length = 0
    if c == "F":
        length += 1
if state_is_rl:
    rl.append(length)
else:
    ud.append(length)

memo_rl = [0] * 8001
memo_ud = [0] * 8001
zeros = [0] * 8001
tmp = [0] * 8001
sum_val = 0
for i, item in enumerate(rl):
    sum_val += item
    tmp = zeros[:]
    if i == 0:
        if x <= rl[0]:
            x = abs(rl[0] - x)
        else:
            x = x - rl[0]
        memo_rl[0] = 1
    else:
        for j in range(sum_val):
            if memo_rl[j] == 1:
                if j - item >= 0:
                    tmp[j - item] = 1
                tmp[j + item] = 1
        memo_rl = tmp[:]

y = abs(y)
memo_ud[0] = 1
for i, item in enumerate(ud):
    sum_val += item
    tmp = zeros[:]
    for j in range(sum_val):
        if memo_ud[j] == 1:
            if j - item >= 0:
                tmp[j - item] = 1
            tmp[j + item] = 1
    memo_ud = tmp[:]

print(memo_rl[:10])
print(memo_ud[:10])
if memo_rl[x] == 1 and memo_ud[y] == 1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

rl = []
ud = []
state_is_rl = True 
length = 0
for c in s:
    if c == "T":
        if state_is_rl:
            rl.append(length)
            state_is_rl = False 
        else:
            ud.append(length)
            state_is_rl = True
        length = 0
    if c == "F":
        length += 1
if state_is_rl:
    rl.append(length)
else:
    ud.append(length)

memo_rl = [0] * 8000
memo_ud = [0] * 8000
zeros = [0] * 8000
tmp = [0] * 8000
sum_val = 0
for i, item in enumerate(rl):
    sum_val += item
    tmp = zeros[:]
    if i == 0:
        if x <= rl[0]:
            x = abs(rl[0] - x)
        else:
            x = x - rl[0]
        memo_rl[0] = 1
    else:
        for j in range(sum_val):
            if memo_rl[j] == 1:
                if j - item >= 0:
                    tmp[j - item] = 1
                tmp[j + item] = 1
        memo_rl = tmp[:]

memo_ud[0] = 1
y = abs(y)
for i, item in enumerate(ud):
    sum_val += item
    tmp = zeros[:]
    for j in range(sum_val):
        if memo_ud[j] == 1:
            if j - item >= 0:
                tmp[j - item] = 1
            tmp[j + item] = 1
    memo_ud = tmp[:]

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

Submission status: Runtime Error

Solution code:
def findsum(array, size, i, s, target):
    if s == target:
        return True
    if i == size:
        return False
    if findsum(array, size, i + 1, s + array[i], target):
        return True
    if findsum(array, size, i + 1, s - array[i], target):
        return True
    return False

def solve():
    s = input()
    gx,gy = map(int,input().split())
    dire = 0
    cnt = 0
    fx = []
    fy = []
    for c in s:
        if c == 'F':
            if dire == 0:
                gx -= 1
            else:
                cnt += 1
        else:
            if dire == 0: # x->y
                dire = 1
                cnt = 0
            elif dire == 1:  # y->x
                if cnt > 0:
                    fy.append(cnt)
                dire = 2
                cnt = 0
            else:            # x->y
                if cnt > 0:
                    fx.append(cnt)
                dire = 1
                cnt = 0
    if dire == 1:    # y
        if cnt > 0:
            fy.append(cnt)
    elif dire == 2:  # x
        if cnt > 0:
            fx.append(cnt)
    if findsum(fx, len(fx), 0, 0, gx):
        if findsum(fy, len(fy), 0, 0, gy):
            return 'Yes'
    return 'No'

print(solve())

Submission status: Runtime Error

Solution code:
def dfs(s, p, l, x, y, ans1, ans2, flag1, flag2):

    if p == l:
        if ans1 == x and ans2 == y:
            print 'Yes'
        else:
            print 'No'

        return

    if s[p] == 'F':

        if flag1 == 1:
            if flag2 == 1:
                ans1 += 1
            else:
                ans1 -= 1
        else:
            if flag2 == 1:
                ans2 += 1
            else:
                ans2 -= 1

        p += 1
        dfs(s, p, l, x, y, ans1, ans2, flag1, flag2)

    else:
        p += 1
        if flag1 == 1:
            flag1 = 2
            if ans2 < y:
                flag2 = 1
            else:
                flag2 = 2
        else:
            flag1 = 1
            if ans1 < x:
                flag2 = 1
            else:
                flag2 = 2

        dfs(s, p, l, x, y, ans1, ans2, flag1, flag2)


s = raw_input()
x, y =  raw_input().split()

dfs(s, 0, len(s), int(x), int(y), 0, 0, 1, 1)

Submission status: Runtime Error

Solution code:
def dfs(s, p, l, x, y, ans1, ans2, flag1, flag2):

    if p == l:
        if ans1 == x and ans2 == y:
            print 'YES'
        else:
            print 'NO'

        return

    if s[p] == 'F':

        if flag1 == 1:
            if flag2 == 1:
                ans1 += 1
            else:
                ans1 -= 1
        else:
            if flag2 == 1:
                ans2 += 1
            else:
                ans2 -= 1

        p += 1
        dfs(s, p, l, x, y, ans1, ans2, flag1, flag2)

    else:
        p += 1
        if flag1 == 1:
            flag1 = 2
            if ans2 < y:
                flag2 = 1
            else:
                flag2 = 2
        else:
            flag1 = 1
            if ans1 < x:
                flag2 = 1
            else:
                flag2 = 2

        dfs(s, p, l, x, y, ans1, ans2, flag1, flag2)


s = raw_input()
x, y =  raw_input().split()

dfs(s, 0, len(s), int(x), int(y), 0, 0, 1, 1)

Submission status: Runtime Error

Solution code:
local deferMeta = {__call = function(t, view, ...)
	local ret = t.__f(view)
	if ret == nil then
		printWarn(tostring(t) .. " is nil")
	end
	return ret
end, __tostring = bindHelperToString}
function bindHelper.defer(f)
	return setmetatable({__bindHelper = true, __method = "defer", __f = f}, deferMeta)
end

Submission status: Runtime Error

Solution code:
from sys import exit

S = str(input())#["F","F","T","F"]
Gx, Gy = [int(n) for n in input().split()]#[4,4]
Xds = []
Yds = []
X = True
L = len(S)
for s in S.split("T"):
    if X:
        Xds.append(len(s))
    else:
        Yds.append(len(s))
    X = not X
# print(Xds)
# print(Yds)
if(len(Xds) != 0):
    memox = [set([Xds[0]])] + [0]*(len(Xds)-1)
else:
    memox = [0]
for i in range(1,len(Xds)):
    can = set()
    for x in memox[i-1]:
        can.add(x+Xds[i])
        can.add(x-Xds[i])
    memox[i]=can

if(len(Yds) != 0):
    memoy = [set([Yds[0],-Yds[0]])] + [0]*(len(Yds)-1)
else:
    memoy = [0]
for i in range(1,len(Yds)):
    can = set()
    for y in memoy[i-1]:
        can.add(y+Yds[i])
        can.add(y-Yds[i])
    memoy[i]=can
if Gx in memox[-1] and Gy in memoy[-1]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
from sys import exit

S = str(input())#["F","F","T","F"]
Gx, Gy = [int(n) for n in input().split()]#[4,4]
Xds = []
Yds = []
X = True
L = len(S)
for s in S.split("T"):
    if X:
        Xds.append(len(s))
    else:
        Yds.append(len(s))
    X = not X
# print(Xds)
# print(Yds)
memox = [[False for _ in range(2*L)] for __ in range(len(Xds))]
memoy = [[False for _ in range(2*L)] for __ in range(len(Yds))]

def move(current, i, Ds,memo):
    if i == len(Ds): return
    pm = current+Ds[i]
    memo[i][pm] = True
    move(pm, i+1,Ds,memo)
    nm = current-Ds[i]
    memo[i][nm] = True
    move(nm, i+1,Ds,memo)
memox[0][Xds[0]] = True
move(Xds[0],1, Xds,memox)
move(0,0, Yds,memoy)
# print(Xds)
# print(Yds)
# print(memox)
# print(memoy)
if not (memox != [] or memoy != []):
    print("Yes" if memox[len(Xds)-1][Gx] and memoy[len(Yds)-1][Gy] else "No")
elif (memox == [] and memoy != []):
    print("Yes" if 0==Gx and memoy[len(Yds)-1][Gy] else "No")
else:
    print("Yes" if memox[len(Xds)-1][Gx] and 0==Gy else "No")

Submission status: Runtime Error

Solution code:
from sys import exit

S = str(input())#["F","F","T","F"]
Gx, Gy = [int(n) for n in input().split()]#[4,4]
Xds = []
Yds = []
X = True
L = len(S)
for s in S.split("T"):
    if X:
        Xds.append(len(s))
    else:
        Yds.append(len(s))
    X = not X
# print(Xds)
# print(Yds)
memox = [[False for _ in range(2*L)] for __ in range(len(Xds))]
memoy = [[False for _ in range(2*L)] for __ in range(len(Yds))]

def move(current, i, Ds,memo):
    if i == len(Ds): return
    pm = current+Ds[i]
    memo[i][pm] = True
    move(pm, i+1,Ds,memo)
    nm = current-Ds[i]
    memo[i][nm] = True
    move(nm, i+1,Ds,memo)
memox[0][Xds[0]] = True
move(Xds[0],1, Xds,memox)
move(0,0, Yds,memoy)
# print(Xds)
# print(Yds)
# print(memox)
# print(memoy)
if not (memox != [] or memoy != []):
    print(memox[len(Xds)-1][Gx] and memoy[len(Yds)-1][Gy])
elif (memox == [] and memoy != []):
    print(0==Gx and memoy[len(Yds)-1][Gy])
else:
    print(memox[len(Xds)-1][Gx] and 0==Gy)

Submission status: Runtime Error

Solution code:
from sys import exit
from enum import Enum
class Direction(Enum):
    xp = 0
    xn = 1
    yp = 2
    yn = 3
def move(S, current, D, G):
    # print(D == Direction.xn)
    # print(S,D,current)
    if(S == []):return current == G
    elif(S[0] == "F"):
        if(D == Direction.xp):
            if move(S[1:],[current[0]+1,current[1]],D,G):return True
        elif(D == Direction.xn):
            if move(S[1:],[current[0]-1,current[1]],D,G):return True
        elif(D == Direction.yp):
            if move(S[1:],[current[0],current[1]+1],D,G):return True
        elif(D == Direction.yn):
            if move(S[1:],[current[0],current[1]-1],D,G):return True
        # del S[0]
    elif(S[0] == "T" and (D == Direction.xp or D == Direction.xn)):
        # del S[0]
        if move(S[1:],current,Direction.yp,G): return True
        if move(S[1:],current,Direction.yn,G): return True
    elif(S[0] == "T" and (D == Direction.yp or D == Direction.yn)):
        # del S[0]
        if move(S[1:],current,Direction.xp,G): return True
        if move(S[1:],current,Direction.xn,G): return True
    return False
current = [0,0]
D = Direction.xp
S = list(input())#["F","F","T","F"]
G = [int(n) for n in input().split()]#[4,4]

if(move(S,current,D,G)):
    print("Yes")
    exit()
else:
    print("No")

Submission status: Runtime Error

Solution code:
s=input()
s+='T'
x,y=map(int,input().split())
n=len(s)
f=0
d=0
xx=[]
yy=[]
for i in range(n):
    if s[i]=='F':
        f+=1
    else: #=='T'
        if f==0:
            0
        else:
            if d==0:
                xx.append(f)
                f=0
            else:
                yy.append(f)
                f=0
        d=1-d

if len(x)>0:
    x[0]=t
    x.remove(x[0])
    xx.append(abs(x-t))
else:
    xx.append(abs(x))
yy.append(abs(y))

#rint(xx,yy)
def judg(a):
    tot=sum(a)
    if tot%2==1:
        return False
    else:
        dp=[0]*(tot+1)
        for i in a:
            dp[i]=1
            for j in range(tot+1):
                if dp[j]==1 and j+i<=tot:
                    dp[j+i]=1
        if dp[int(tot/2)]==1:
            return True
        else:
            return False
if judg(xx) and judg(yy):
    ans='Yes'
else:
    ans='No'
print(ans)