Problem:


Score : 500 points

Problem Statement

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

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

F : Move in the current direction by distance 1.

T : Turn 90 degrees, either clockwise or counterclockwise.

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

Constraints

s consists of F and T.

1 \leq |s| \leq 8 000

x and y are integers.

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

Input

Input is given from Standard Input in the following format:

s
x y

Output

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

Sample Input 1

FTFFTFFF
4 2

Sample Output 1

Yes

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

Sample Input 2

FTFFTFFF
-2 -2

Sample Output 2

Yes

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

Sample Input 3

FF
1 0

Sample Output 3

No

Sample Input 4

TF
1 0

Sample Output 4

No

Sample Input 5

FFTTFF
0 0

Sample Output 5

Yes

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

Sample Input 6

TTTT
1 0

Sample Output 6

No



Sample input:
FTFFTFFF
4 2


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
wayx = []
wayy = []
pad = 10000


state = True
seq = 0
for c in s:
    if c == "T":
        if state:
            wayx.append(seq)
            seq = 0
            state = False
        else:
            wayy.append(seq)
            seq = 0
            state = True
    else:
        seq += 1



if state:
    wayx.append(seq)
    seq = 0
    state = False
else:
    wayy.append(seq)
    seq = 0
    state = True

can_reachx = [[False for i in range(pad*2+1)] for j in range(len(wayx)+1)]
can_reachy = [[False for i in range(pad*2+1)] for j in range(len(wayy)+1)]
can_reachx[0][pad] = True
can_reachy[0][pad] = True

for i in range(len(wayx)):
    w = wayx[i]
    for j in range(pad*2+1):
        if can_reachx[i][j]:
            can_reachx[i+1][j+w] = True
            can_reachx[i+1][j-w] = True

for i in range(len(wayy)):
    w = wayy[i]
    for j in range(pad*2+1):
        if can_reachy[i][j]:
            can_reachy[i+1][j+w] = True
            can_reachy[i+1][j-w] = True


if can_reachx[-1][x+pad] and can_reachy[-1][y+pad]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
wayx = []
wayy = []
pad = 15000


state = True
seq = 0
for c in s:
    if c == "T":
        if state:
            wayx.append(seq)
            seq = 0
            state = False
        else:
            wayy.append(seq)
            seq = 0
            state = True
    else:
        seq += 1



if state:
    wayx.append(seq)
    seq = 0
    state = False
else:
    wayy.append(seq)
    seq = 0
    state = True

can_reachx = [[False for i in range(pad*2+1)] for j in range(len(wayx)+1)]
can_reachy = [[False for i in range(pad*2+1)] for j in range(len(wayy)+1)]
can_reachx[0][pad] = True
can_reachy[0][pad] = True



for i in range(len(wayx)):
    w = wayx[i]
    for j in range(pad*2+1):
        if can_reachx[i][j]:
            if j+w <= pad*2:
                can_reachx[i+1][j+w] = True
            if j-w >= 0:
                can_reachx[i+1][j-w] = True

for i in range(len(wayy)):
    w = wayy[i]
    for j in range(pad*2+1):
        if can_reachy[i][j]:
            if j+w <= pad*2:
                can_reachy[i+1][j+w] = True
            if j-w >= 0:
                can_reachy[i+1][j-w] = True

# print(wayx)
# print(wayy)
if can_reachx[-1][x+pad] and can_reachy[-1][y+pad]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
wayx = []
wayy = []
pad = 15000
can_reachx = [False for i in range(pad*2+1)]
can_reachy = [False for i in range(pad*2+1)]
can_reachx[pad] = True
can_reachy[pad] = True

state = True
seq = 0
for c in s:
    if c == "T":
        if state:
            wayx.append(seq)
            seq = 0
            state = False
        else:
            wayy.append(seq)
            seq = 0
            state = True
    else:
        seq += 1



if state:
    wayx.append(seq)
    seq = 0
    state = False
else:
    wayy.append(seq)
    seq = 0
    state = True



for w in wayx:
    b = []
    buf = [False for i in range(pad*2+1)]
    for i in range(len(can_reachx)):
        if can_reachx[i]:
            if i+w <= pad*2:
                buf[i+w] = True
            if i-w >= 0:
                buf[i-w] = True
    can_reachx = buf

for w in wayy:
    b = []
    buf = [False for i in range(pad * 2 + 1)]
    for i in range(len(can_reachy)):
        if can_reachy[i]:
            if i+w <= pad*2:
                buf[i+w] = True
            if i-w >= 0:
                buf[i-w] = True
    can_reachy = buf

# print(wayx)
# print(wayy)
if can_reachx[x+pad] and can_reachy[y+pad]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
wayx = []
wayy = []
pad = 15000
can_reachx = [False for i in range(pad*2+1)]
can_reachy = [False for i in range(pad*2+1)]
can_reachx[pad] = True
can_reachy[pad] = True

state = True
seq = 0
for c in s:
    if c == "T":
        if state:
            wayx.append(seq)
            seq = 0
            state = False
        else:
            wayy.append(seq)
            seq = 0
            state = True
    else:
        seq += 1



if state:
    wayx.append(seq)
    seq = 0
    state = False
else:
    wayy.append(seq)
    seq = 0
    state = True



for w in wayx:
    b = []
    for i in range(len(can_reachx)):
        if can_reachx[i]:
            if i+w <= pad*2:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
            if w != 0:
                can_reachx[i] = False
    for t in b:
        can_reachx[t] = True

for w in wayy:
    b = []
    for i in range(len(can_reachy)):
        if can_reachy[i]:
            if i+w <= pad*2:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
            if w != 0:
                can_reachx[i] = False
    for t in b:
        can_reachy[t] = True

# print(wayx)
# print(wayy)
if can_reachx[x+pad] and can_reachy[y+pad]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
wayx = []
wayy = []
pad = 20000
can_reachx = [False for i in range(pad*2+1)]
can_reachy = [False for i in range(pad*2+1)]
can_reachx[pad] = True
can_reachy[pad] = True

state = True
seq = 0
for c in s:
    if c == "T":
        if state:
            wayx.append(seq)
            seq = 0
            state = False
        else:
            wayy.append(seq)
            seq = 0
            state = True
    else:
        seq += 1



if state:
    wayx.append(seq)
    seq = 0
    state = False
else:
    wayy.append(seq)
    seq = 0
    state = True



for w in wayx:
    b = []
    for i in range(len(can_reachx)):
        if can_reachx[i]:
            if i+w <= pad*2:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
            can_reachx[i] = False
    for t in b:
        can_reachx[t] = True

for w in wayy:
    b = []
    for i in range(len(can_reachy)):
        if can_reachy[i]:
            if i+w <= pad*2:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
            can_reachx[i] = False
    for t in b:
        can_reachy[t] = True

# print(wayx)
# print(wayy)
if can_reachx[x+pad] and can_reachy[y+pad]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
wayx = []
wayy = []
pad = 20000
can_reachx = [False for i in range(pad*2+1)]
can_reachy = [False for i in range(pad*2+1)]
can_reachx[pad] = True
can_reachy[pad] = True

state = True
seq = 0
for c in s:
    if c == "T":
        if state:
            wayx.append(seq)
            seq = 0
            state = False
        else:
            wayy.append(seq)
            seq = 0
            state = True
    else:
        seq += 1



if state:
    wayx.append(seq)
    seq = 0
    state = False
else:
    wayy.append(seq)
    seq = 0
    state = True



for w in wayx:
    b = []
    for i in range(len(can_reachx)):
        if can_reachx[i]:
            if i+w <= pad*2:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
    for t in b:
        can_reachx[t] = True

for w in wayy:
    b = []
    for i in range(len(can_reachy)):
        if can_reachy[i]:
            if i+w <= pad*2:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
    for t in b:
        can_reachy[t] = True

# print(wayx)
# print(wayy)
if can_reachx[x+pad] and can_reachy[y+pad]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
wayx = []
wayy = []
can_reachx = [False for i in range(10000*2+1)]
can_reachy = [False for i in range(10000*2+1)]
can_reachx[10000] = True
can_reachy[10000] = True

state = True
seq = 0
for c in s:
    if c == "T":
        if state:
            wayx.append(seq)
            seq = 0
            state = False
        else:
            wayy.append(seq)
            seq = 0
            state = True
    else:
        seq += 1


if state:
    wayx.append(seq)
    seq = 0
    state = False
else:
    wayy.append(seq)
    seq = 0
    state = True

for w in wayx:
    b = []
    for i in range(len(can_reachx)):
        if can_reachx[i]:
            if i+w <= 20000:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
    for t in b:
        can_reachx[t] = True

for w in wayy:
    b = []
    for i in range(len(can_reachy)):
        if can_reachy[i]:
            if i+w <= 20000:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
    for t in b:
        can_reachy[t] = True

# print(wayx)
# print(wayy)
if can_reachx[x+10000] and can_reachy[y+10000]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
wayx = []
wayy = []
can_reachx = [False for i in range(8000*2+1)]
can_reachy = [False for i in range(8000*2+1)]
can_reachx[8000] = True
can_reachy[8000] = True

state = True
seq = 0
for c in s:
    if c == "T":
        if state:
            wayx.append(seq)
            seq = 0
            state = False
        else:
            wayy.append(seq)
            seq = 0
            state = True
    else:
        seq += 1


if state:
    wayx.append(seq)
    seq = 0
    state = False
else:
    wayy.append(seq)
    seq = 0
    state = True

for w in wayx:
    b = []
    for i in range(len(can_reachx)):
        if can_reachx[i]:
            if i+w <= 16000:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
    for t in b:
        can_reachx[t] = True

for w in wayy:
    b = []
    for i in range(len(can_reachy)):
        if can_reachy[i]:
            if i+w <= 16000:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
    for t in b:
        can_reachy[t] = True

# print(wayx)
# print(wayy)
if can_reachx[x+8000] and can_reachy[y+8000]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
def cango(l,x):
    n=sum(l)
    if abs(x)>n:
        return False
    dp=[False]*(n+1)
    dp[0]=True
    for i in range(len(l)):
        dp1=[False]*(n+1)
        for j in range(n+1):
            if dp[j]:
                dp1[abs(j-l[i])]=True
                dp1[j+l[i]]=True
        for i in range(n+1):
            dp[i]=dp1[i]
    return dp[abs(x)]

l=eval("['"+input().replace('T',"','")+"']")
for i in range(len(l)):
    l[i]=len(l[i])
x,y=map(int,input().split())
if len(l)==1:
    print(['No','Yes'][x==l[0] and y==0])
elif len(l)==2:
    print(['No','Yes'][x==l[0] and y==l[1]])
else:
    print(['No','Yes'][cango(l[2::2],x-l[0]) and cango(l[1::2],y)])

Submission status: Wrong Answer

Solution code:
def cango(l,x):
    n=sum(l)
    if abs(x)>n:
        return False
    dp=[False]*(n+1)
    dp[0]=True
    for i in range(len(l)):
        dp1=[False]*(n+1)
        for j in range(n+1):
            if dp[j]:
                dp1[abs(j-l[i])]=True
                dp1[j+l[i]]=True
        for i in range(n+1):
            dp[i]=dp1[i]
    return dp[abs(x)]

l=eval("['"+input().replace('T',"','")+"']")
for i in range(len(l)):
    l[i]=len(l[i])
x,y=map(int,input().split())
if len(l)==1:
    print(['No','Yes'][x==l[0] and y==0])
else:
    print(['No','Yes'][cango(l[::2],x) and cango(l[1::2],y)])

Submission status: Wrong Answer

Solution code:
s = list(map(len,input().split("T")))
x = s[::2]
y = s[1::2]
gx,gy = map(int,input().split())
if sum(x) < abs(gx) or sum(y) < abs(gy):
  print("No")
  exit(0)
dpx = [0]*(len(x)+1)
dpy = [0]*(len(y)+1)
dpx[0] = set([0])
dpy[0] = set([0])
for i in range(1,len(x)+1):
  s1 = set([v + x[i-1] for v in dpx[i-1]])
  s2 = set([v - x[i-1] for v in dpx[i-1]])
  dpx[i] = s1|s2
for i in range(1,len(y)+1):
  s1 = set([v + y[i-1] for v in dpy[i-1]])
  s2 = set([v - y[i-1] for v in dpy[i-1]])
  dpy[i] = s1|s2
if gx in dpx[-1] and gy in dpy[-1]:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
from itertools import product

s = input()
xy = list(map(int, input().split()))

ewns = [[], []]
count = flag = 0
for c in s :
    if c == "F" :
        count += 1
    else :
        ewns[flag].append(count)
        count = 0
        flag ^= 1
else :
    ewns[flag].append(count)

iterproduct = lambda iter1, iter2 : sum(i*j for i, j in zip(iter1, iter2))

prob = [[iterproduct(ewns[i], l) for l in product([1, -1], repeat=len(ewns[i]))] for i in range(2)]
print("Yes" if all(xy[i] in prob[i] for i in range(2)) else "No")

Submission status: Wrong Answer

Solution code:
def resolve():
    s = input()
    x, y = map(int, input().split())
    d = {1: 0, -1: 0}  # x, y
    direction = 1
    for c in s:
        if c == "F":
            d[direction] += 1
        else:
            direction *= -1
    if abs(x) <= d[1] and x % 2 == d[1] % 2 and abs(y) <= d[-1] and y % 2 == d[-1] % 2:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
"""
a, b = LI()
print((a+b+1)//2)
"""

#B
"""
a = S()
a = a[:-1]
b = S()
b = b[:-1]
a.sort()
b.sort(reverse=True)
if a < b:
    print("Yes")
else:
    print("No")
"""

#C
"""
n = I()
a = LI()
a.sort()
seta = set(a)
ans = 0
for i in seta:
    x = bisect.bisect_right(a,i) - bisect.bisect_left(a,i)
    if x != 0 and x >= i:
        ans += x - i
    else:
        ans += x
print(ans)        
"""

#D
s = S()
X, Y = LI()
move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
d = defaultdict(int)
dia = 0
d[(0,0,0)] = True
for i in s:
    if i == "T":
        dia += 1
    else:
        nd = defaultdict(int)
        for key, value in d.items():
            x, y, di = key
            di1 = (di + dia) % 4
            di2 = (di - dia) % 4
            nd[(x + move[di1][0], y + move[di1][1], di1)] = True
            nd[(x + move[di2][0], y + move[di2][1], di2)] = True
        d = nd
        dia = 0
for i in range(4):
    if d[(X, Y, i)]:
        print("Yes")
        quit()
print("No")

Submission status: Wrong Answer

Solution code:
def main():
    s = list(input())
    s.append("T")
    x,y = map(int,input().split())
    x_list = []
    y_list = []
    count = 0
    n = 0
    for i in range(len(s)):
        if s[i] == "F":
            count += 1
        else:
            if n == 0:
                x_list.append(count)
                n = 1
            else:
                y_list.append(count)
                n = 0
            count = 0
    x_def = {0}
    for i in x_list:
        x__def = set()
        for j in x_def:
            x__def.add(j+i)
            x__def.add(j-i)
        x_def = x__def
    if x not in x_def:
        print("No")
        exit()

    y_def = {0}
    for i in y_list:
        y__def = set()
        for j in y_def:
            y__def.add(j+i)
            y__def.add(j-i)
        y_def = y__def
    if y not in y_def:
        print("No")
        exit()
    print("Yes")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    s = input().split("T")
    x, y = map(int, input().split())
    xs = []
    x -= len(s[0])
    for i in range(2, len(s), 2):
        tmp = len(s[i])
        if tmp != 0:
            xs.append(tmp)
    ys = []
    for i in range(1, len(s), 2):
        tmp = len(s[i])
        if tmp != 0:
            ys.append(tmp)
    
    sum_x = sum(xs)
    sum_y = sum(ys)
    x = abs(x)
    y = abs(y)
    if sum_x < x or sum_y < y:
        print("No")
    else:
        rest_x = sum_x - x
        rest_y = sum_y - y
        if rest_x&1 or rest_y&1:
            print("No")
        else:
            ok = True
            if rest_x > 0:
                dp = np.array([[False]*8001 for i in range(len(xs)+1)])
                dp[0][0] = True
                for i in range(1, len(xs)+1):
                    # dp[i] = dp[i] | dp[i-1]
                    dp[i][xs[i-1]:] = dp[i-1][xs[i-1]:] | dp[i-1][:-xs[i-1]]
                    dp[i][:-xs[i-1]] = dp[i-1][:-xs[i-1]] | dp[i-1][xs[i-1]:]
                if not dp[-1][rest_x//2]:
                    ok = False
            if rest_y > 0:
                dp = np.array([[False]*8001 for i in range(len(ys)+1)])
                dp[0][0] = True
                for i in range(1, len(ys)+1):
                    # dp[i] = dp[i] | dp[i-1]
                    dp[i][ys[i-1]:] = dp[i-1][ys[i-1]:] | dp[i-1][:-ys[i-1]]
                    dp[i][:-ys[i-1]] = dp[i-1][:-ys[i-1]] | dp[i-1][ys[i-1]:]
                if not dp[-1][rest_y//2]:
                    ok = False
            if ok:
                print("Yes")
            else:
                print("No")
                    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    s = input().split("T")
    x, y = map(int, input().split())
    
    print("No")                

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    s = input().split("T")
    x, y = map(int, input().split())
    xs = []
    x -= len(s[0])
    for i in range(2, len(s), 2):
        tmp = len(s[i])
        if tmp != 0:
            xs.append(tmp)
    ys = []
    for i in range(1, len(s), 2):
        tmp = len(s[i])
        if tmp != 0:
            ys.append(tmp)
    
    sum_x = sum(xs)
    sum_y = sum(ys)
    x = abs(x)
    y = abs(y)
    if sum_x < x or sum_y < y:
        print("No")
    else:
        rest_x = sum_x - x
        rest_y = sum_y - y
        if rest_x&1 or rest_y&1:
            print("No")
        else:
            ok = True
            if rest_x > 0:
                dp = np.array([[False]*8001 for i in range(len(xs)+1)])
                dp[0][0] = True
                for i in range(1, len(xs)+1):
                    dp[i] = dp[i] | dp[i-1]
                    dp[i][xs[i-1]:] = dp[i][xs[i-1]:] | dp[i-1][:-xs[i-1]]
                    dp[i][:-xs[i-1]] = dp[i][:-xs[i-1]] | dp[i-1][xs[i-1]:]
                if not dp[-1][rest_x//2]:
                    ok = False
            if rest_y > 0:
                dp = np.array([[False]*8001 for i in range(len(ys)+1)])
                dp[0][0] = True
                for i in range(1, len(ys)+1):
                    dp[i] = dp[i] | dp[i-1]
                    dp[i][ys[i-1]:] = dp[i][ys[i-1]:] | dp[i-1][:-ys[i-1]]
                    dp[i][:-ys[i-1]] = dp[i][:-ys[i-1]] | dp[i-1][ys[i-1]:]
                if not dp[-1][rest_y//2]:
                    ok = False
            if ok:
                print("Yes")
            else:
                print("No")
                    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    s = input().split("T")
    x, y = map(int, input().split())
    xs = []
    x -= len(s[0])
    for i in range(2, len(s), 2):
        tmp = len(s[i])
        if tmp != 0:
            xs.append(tmp)
    ys = []
    for i in range(1, len(s), 2):
        tmp = len(s[i])
        if tmp != 0:
            ys.append(tmp)
    
    sum_x = sum(xs)
    sum_y = sum(ys)
    x = abs(x)
    y = abs(y)
    if sum_x < x or sum_y < y:
        print("No")
    else:
        rest_x = sum_x - x
        rest_y = sum_y - y
        if rest_x&1 or rest_y&1:
            print("No")
        else:
            ok = True
            if rest_x > 0:
                dp = np.array([[False]*8001 for i in range(len(xs)+1)])
                dp[0][0] = True
                for i in range(1, len(xs)+1):
                    dp[i] = dp[i] | dp[i-1]
                    dp[i][xs[i-1]:] = dp[i][xs[i-1]] | dp[i-1][:-xs[i-1]]
                    dp[i][:-xs[i-1]] = dp[i][:-xs[i-1]] | dp[i-1][xs[i-1]:]
                if not dp[-1][rest_x//2]:
                    ok = False
            if rest_y > 0:
                dp = np.array([[False]*8001 for i in range(len(ys)+1)])
                dp[0][0] = True
                for i in range(1, len(ys)+1):
                    dp[i] = dp[i] | dp[i-1]
                    dp[i][ys[i-1]:] = dp[i][ys[i-1]] | dp[i-1][:-ys[i-1]]
                    dp[i][:-ys[i-1]] = dp[i][:-ys[i-1]] | dp[i-1][ys[i-1]:]
                if not dp[-1][rest_y//2]:
                    ok = False
            if ok:
                print("Yes")
            else:
                print("No")
                    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    s = input().split("T")
    x, y = map(int, input().split())
    xs = []
    x -= len(s[0])
    for i in range(2, len(s), 2):
        tmp = len(s[i])
        if tmp != 0:
            xs.append(tmp)
    ys = []
    for i in range(1, len(s), 2):
        tmp = len(s[i])
        if tmp != 0:
            ys.append(tmp)
    
    sum_x = sum(xs)
    sum_y = sum(ys)
    x = abs(x)
    y = abs(y)
    if sum_x < x or sum_y < y:
        print("No")
    else:
        rest_x = sum_x - x
        rest_y = sum_y - y
        if rest_x&1 or rest_y&1:
            print("No")
        else:
            ok = True
            if rest_x > 0:
                dp = np.array([[False]*8001 for i in range(len(xs)+1)])
                dp[0][0] = True
                for i in range(1, len(xs)+1):
                    dp[i] = dp[i-1]
                    dp[i][xs[i-1]:] = dp[i][xs[i-1]] | dp[i-1][:-xs[i-1]]
                    dp[i][:-xs[i-1]] = dp[i][:-xs[i-1]] | dp[i-1][xs[i-1]:]
                if not dp[-1][rest_x//2]:
                    ok = False
            if rest_y > 0:
                dp = np.array([[False]*8001 for i in range(len(ys)+1)])
                dp[0][0] = True
                for i in range(1, len(ys)+1):
                    dp[i] = dp[i-1]
                    dp[i][ys[i-1]:] = dp[i][ys[i-1]] | dp[i-1][:-ys[i-1]]
                    dp[i][:-ys[i-1]] = dp[i][:-ys[i-1]] | dp[i-1][ys[i-1]:]
                if not dp[-1][rest_y//2]:
                    ok = False
            if ok:
                print("Yes")
            else:
                print("No")
                    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
xy = input()
print("Yes")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as d
s=input()+"T"
x,y=map(int,input().split())
p=[[],[]]
c,e=0,0
for i in s:
    if i=="T":
        if e!=0:
            p[c].append(e)
            e=0
        c=(c+1)%2
    else:
        e+=1
def f(a,c,q):
    g=d(int)
    if q!=0:
        if len(a)>0 and s[0]=="F":
            g[a[0]]=1
        else:
            g[0]=1
    else:
        g[0]=1
    for j in a[q:]:
        t=d(int)
        for i,h in g.items():
            t[i-j]=1
            t[i+j]=1
        else:
            g=t
    return g[c]!=0
print("Yes" if f(p[0],x,1)*f(p[1],y,0)==1 else"No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as d
s=input()+"T"
x,y=map(int,input().split())
p=[[],[]]
c,e=0,0
for i in s:
    if i=="T":
        if e!=0:
            p[c].append(e)
            e=0
        c=(c+1)%2
    else:
        e+=1
def f(a,c,q):
    g=d(int)
    if q!=0:
        if len(a)>0:
            g[a[0]]=1
        else:
            g[0]=1
    else:
        g[0]=1
    for j in a[q:]:
        t=d(int)
        for i,h in g.items():
            t[i-j]=1
            t[i+j]=1
        else:
            g=t
    print(g)
    return g[c]!=0
print("Yes" if f(p[0],x,1)*f(p[1],y,0)==1 else"No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as d
s=input()+"T"
x,y=map(int,input().split())
p=[[],[]]
c,e=0,0
for i in s:
    if i=="T":
        if e!=0:
            p[c].append(e)
            e=0
        c=(c+1)%2
    else:
        e+=1
def f(a,c):
    g=d(int)
    g[0]=1
    for j in a:
        t=d(int)
        for i,h in g.items():
            t[i-j]=1
            t[i+j]=1
        else:
            g=t
    return g[c]!=0
print("Yes" if f(p[0],x)*f(p[1],y)==1 else"No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as d
s=input()
x,y=map(int,input().split())
p=[[],[]]
c,e=0,0
for i in s:
    if i=="T":
        if e!=0:
            p[c].append(e)
            e=0
        c=(c+1)%2
    else:
        e+=1
if e!=0:
    p[c].append(e)
u=0
for i in s:
    if i=="T":
        u=(u+1)%2
    else:
        break
def f(a,c):
    g=d(int)
    g[0]=1
    for j in a:
        t=d(int)
        for i,h in g.items():
            t[i-j]=1
            t[i+j]=1
        else:
            g=t
    return g[c]!=0
print("Yes" if f(p[u],x)*f(p[1-u],y)==1 else"No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as d
s=input()
x,y=map(int,input().split())
p=[[],[]]
c,e=0,0
for i in s:
    if i=="T":
        if e!=0:
            p[c].append(e)
            e=0
        c=(c+1)%2
    else:
        e+=1
if e!=0:
    p[c].append(e)
u=0
for i in s:
    if i=="T":
        u=(u+1)%2
    else:
        break
def f(a,c):
    g=d(int)
    g[0]=0
    for j in a:
        t=d(int)
        for i,h in g.items():
            t[i-j]=1
            t[i+j]=1
        else:
            g=t
    return g[c]!=0
print("Yes" if f(p[u],x)*f(p[1-u],y)==1 else"No")

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
p=[[],[]]
c,d=0,0
for i in s:
    if i=="T":
        if d!=0:
            p[c].append(d)
            d=0
        c=(c+1)%2
    else:
        d+=1
if d!=0:
    p[c].append(d)
u=0
for i in s:
    if i=="T":
        u=(u+1)%2
    else:
        break
def f(a,c):
    g={0:1}
    for j in a:
        t={}
        for i in g:
            if i-j not in t:
                t[i-j]=1
            if i+j not in t:
                t[i+j]=1
        else:
            g=t
    return c in g
print("Yes" if f(p[u],x)*f(p[1-u],y)==1 else"No")

Submission status: Wrong Answer

Solution code:
s = input()
X, Y = map(int, input().split())
fs = s.split("T")
nsx = list(map(len, fs[0::2]))
nsy = list(map(len, fs[1::2]))
dp = [[False]*16000 for i in range(len(nsx)+1)]
dp[0][0] = True
dp[1][nsx[0]] = True
for i in range(1, len(nsx)):
  n = nsx[i]
  for x in range(-8000, 8000):
    dp[i+1][x] = dp[i][x+n]|dp[i][x-n]
okx = dp[len(nsx)][X]
dp = [[False]*16000 for i in range(len(nsy)+1)]
dp[0][0] = True
for i in range(0, len(nsy)):
  n = nsy[i]
  for y in range(-8000, 8000):
    dp[i+1][y] = dp[i][y+n]|dp[i][y-n]
oky = dp[len(nsy)][Y]
if okx and oky:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s = input()
order = [s[i] for i in range (len(s))]
x,y = map(int, input().split())

x_f = 0
y_f = 0
x_direction = ["x"]

for i in range(len(order)):
  if order[i]=="T" and x_direction[i]=="x": #i番目の操作前の方向
    x_direction.append("y")
  elif order[i]=="T" and x_direction[i]=="y":
    x_direction.append("x")
  elif order[i]=="F" and x_direction[i]=="x":
    x_f += 1
    x_direction.append("x")
  elif order[i]=="F" and x_direction[i]=="y":
    y_f += 1
    x_direction.append("y")

if x%2==x_f%2 and y%2==y_f%2 and x_f>=abs(x) and y_f>=abs(y):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s = input()
order = [s[i] for i in range (len(s))]
x,y = map(int, input().split())

x_f = 0
y_f = 0
x_direction = ["x"]

for i in range(len(order)):
  if order[i]=="T" and x_direction[i]=="x": #i番目の操作前の方向
    x_direction.append("y")
  elif order[i]=="T" and x_direction[i]=="y":
    x_direction.append("x")
  elif order[i]=="F" and x_direction[i]=="x":
    x_f += 1
    x_direction.append("x")
  else:
    y_f += 1
    x_direction.append("y")

if x%2==x_f%2 and y%2==y_f%2 and x_f>=abs(x) and y_f>=abs(y):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s = input()
order = [s[i] for i in range (len(s))]
x,y = map(int, input().split())

x_f = 0
y_f = 0
x_direction = True

for i in range(len(order)):
  if order[i]=="T" and x_direction:
    x_direciton = False
  elif order[i]=="T":
    x_direction = True
  elif order[i]=="F" and x_direction:
    x_f += 1
  else:
    y_f += 1

if x%2==x_f%2 and y%2==y_f%2 and x_f>=abs(x) and y_f>=abs(y):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s = input()
order = [s[i] for i in range (len(s))]
x,y = map(int, input().split())

x_f = 0
y_f = 0
x_direction = True

for i in range(len(order)):
  if order[i]=="T" and x_direction:
    x_direciton = False
  elif order[i]=="T":
    x_direction = True
  elif order[i]=="F" and x_direction:
    x_f += 1
  else:
    y_f += 1

if x%2==x_f%2 and y%2==y_f%2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
def isReach( goal, move ):
    msum = sum(move)
    m = len(move)

    if msum < abs(goal):
        return False

    dp = [[False]*(msum*2+1) for i in range(m+1)]
    dp[0][0] = True
    
    for i in range(m):
        for j in range(-msum,msum+1):
            if dp[i][j]:
                dp[i+1][j-move[i]] = True
                dp[i+1][j+move[i]] = True
    
    return dp[m][goal]


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

move_dist = [len(move) for move in s]
x_move = move_dist[0::2]
y_move = move_dist[1::2]

if isReach(x,x_move) and isReach(y,y_move):
    print('Yes')
else:
    print('No')