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())

susumu = s.count("F")
if susumu % 2 != (x + y) % 2:
    print("No")
    exit()
if susumu < (x + y):
    print("No")
    exit()
x_houkou = True
cnt = 0
X = []
Y = []
for w in s:
    if w == "F":
        cnt += 1
    else:
        if x_houkou:
            X.append(cnt)
            cnt = 0
            x_houkou = False
        else:
            Y.append(cnt)
            cnt = 0
            x_houkou = True
if cnt > 0:
    if x_houkou:
        X.append(cnt)
    else:
        Y.append(cnt)

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


x_ok = False
y_ok = False
if not X:
    if x == 0:
        x_ok = True
    else:
        print("No")
        exit()
if not Y:
    if y == 0:
        y_ok = True
    else:
        print("No")
        exit()

x = abs(x)
y = abs(y)
x_num = len(X)
y_num = len(Y)
if not x_ok:
    dp1 = [0] * (2 * 8000 + 1)
    dp2 = [0] * (2 * 8000 + 1)
    dp1[8000] = 1
    for j in range(x_num):
        if j % 2 == 0:
            t = X[j]
            for i in range(2 * 8000, -1, -1):
                if dp1[i] == 1:
                    if i + t <= 2 * 8000:
                        dp2[i + t] = 1
                    if i - t >= 0:
                        dp2[i + t] = 1
        else:
            t = X[j]
            for i in range(2 * 8000, -1, -1):
                if dp2[i] == 1:
                    if i + t <= 2 * 8000:
                        dp1[i + t] = 1
                    if i - t >= 0:
                        dp1[i + t] = 1
    if x_num % 2 == 1:
        x_ok += dp2[8000 + x]
    else:
        x_ok += dp1[8000 + x]

if not y_ok:
    dp1 = [0] * (2 * 8000 + 1)
    dp2 = [0] * (2 * 8000 + 1)
    dp1[8000] = 1
    for j in range(y_num):
        if j % 2 == 0:
            t = Y[j]
            for i in range(2 * 8000, -1, -1):
                if dp1[i] == 1:
                    if i + t <= 2 * 8000:
                        dp2[i + t] = 1
                    if i - t >= 0:
                        dp2[i + t] = 1
        else:
            t = Y[j]
            for i in range(2 * 8000, -1, -1):
                if dp2[i] == 1:
                    if i + t <= 2 * 8000:
                        dp1[i + t] = 1
                    if i - t >= 0:
                        dp1[i + t] = 1
    if y_num % 2 == 1:
        y_ok += dp2[8000 + y]
    else:
        y_ok += dp1[8000 + y]

if x_ok and y_ok:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
if s[0] == "F":
    x_choku = True
else:
    x_choku = False
# susumu = s.count("F")
# if susumu % 2 != (x + y) % 2:
#     print("No")
#     exit()
# if susumu < (x + y):
#     print("No")
#     exit()
x_houkou = True
cnt = 0
X = []
Y = []
for w in s:
    if w == "F":
        cnt += 1
    else:
        if x_houkou:
            X.append(cnt)
            cnt = 0
            x_houkou = False
        else:
            Y.append(cnt)
            cnt = 0
            x_houkou = True
if cnt > 0:
    if x_houkou:
        X.append(cnt)
    else:
        Y.append(cnt)
if x_choku:
    x -= X[0]
    X = X[1::]


x_ok = False
y_ok = False
if not X:
    if x == 0:
        x_ok = True
    else:
        print("No")
        exit()
if not Y:
    if y == 0:
        y_ok = True
    else:
        print("No")
        exit()

x = abs(x)
y = abs(y)
x_num = len(X)
y_num = len(Y)
if not x_ok:
    dp1 = [0] * (8000 + 1)
    dp2 = [0] * (8000 + 1)
    dp1[0] = 1
    for j in range(x_num):
        if j % 2 == 0:
            t = X[j]
            for i in range(8000, -1, -1):
                if dp1[i] == 1:
                    if i + t <= 8000:
                        dp2[i + t] = 1
                    if i - t >= 0:
                        dp2[i + t] = 1
        else:
            t = X[j]
            for i in range(8000, -1, -1):
                if dp2[i] == 1:
                    if i + t <= 8000:
                        dp1[i + t] = 1
                    if i - t >= 0:
                        dp1[i + t] = 1
    if x_num % 2 == 1:
        x_ok += dp2[x]
    else:
        x_ok += dp1[x]

if not y_ok:
    dp1 = [0] * (8000 + 1)
    dp2 = [0] * (8000 + 1)
    dp1[0] = 1
    for j in range(y_num):
        if j % 2 == 0:
            t = Y[j]
            for i in range(8000, -1, -1):
                if dp1[i] == 1:
                    if i + t <= 8000:
                        dp2[i + t] = 1
                    if i - t >= 0:
                        dp2[i + t] = 1
        else:
            t = Y[j]
            for i in range(8000, -1, -1):
                if dp2[i] == 1:
                    if i + t <= 8000:
                        dp1[i + t] = 1
                    if i - t >= 0:
                        dp1[i + t] = 1
    if y_num % 2 == 1:
        y_ok += dp2[y]
    else:
        y_ok += dp1[y]

if x_ok and y_ok:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
if s[0] == "F":
    x_choku = True
else:
    x_choku = False
susumu = s.count("F")
if susumu % 2 != (x + y) % 2:
    print("No")
    exit()
if susumu < (x + y):
    print("No")
    exit()
x_houkou = True
cnt = 0
X = []
Y = []
for w in s:
    if w == "F":
        cnt += 1
    else:
        if x_houkou:
            X.append(cnt)
            cnt = 0
            x_houkou = False
        else:
            Y.append(cnt)
            cnt = 0
            x_houkou = True
if cnt > 0:
    if x_houkou:
        X.append(cnt)
    else:
        Y.append(cnt)
if x_choku:
    x -= X[0]
    X = X[1::]


x_ok = False
y_ok = False
if not X:
    if x == 0:
        x_ok = True
    else:
        print("No")
        exit()
if not Y:
    if y == 0:
        y_ok = True
    else:
        print("No")
        exit()

x = abs(x)
y = abs(y)
x_num = len(X)
y_num = len(Y)
if not x_ok:
    dp1 = [0] * (8000 + 1)
    dp2 = [0] * (8000 + 1)
    dp1[0] = 1
    for j in range(x_num):
        if j % 2 == 0:
            t = X[j]
            for i in range(8000, -1, -1):
                if dp1[i] == 1:
                    if i + t <= 8000:
                        dp2[i + t] = 1
                    if i - t >= 0:
                        dp2[i + t] = 1
        else:
            t = X[j]
            for i in range(8000, -1, -1):
                if dp2[i] == 1:
                    if i + t <= 8000:
                        dp1[i + t] = 1
                    if i - t >= 0:
                        dp1[i + t] = 1
    if x_num % 2 == 1:
        x_ok += dp2[x]
    else:
        x_ok += dp1[x]

if not y_ok:
    dp1 = [0] * (8000 + 1)
    dp2 = [0] * (8000 + 1)
    dp1[0] = 1
    for j in range(y_num):
        if j % 2 == 0:
            t = Y[j]
            for i in range(8000, -1, -1):
                if dp1[i] == 1:
                    if i + t <= 8000:
                        dp2[i + t] = 1
                    if i - t >= 0:
                        dp2[i + t] = 1
        else:
            t = Y[j]
            for i in range(8000, -1, -1):
                if dp2[i] == 1:
                    if i + t <= 8000:
                        dp1[i + t] = 1
                    if i - t >= 0:
                        dp1[i + t] = 1
    if y_num % 2 == 1:
        y_ok += dp2[y]
    else:
        y_ok += dp1[y]

if x_ok and y_ok:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
if s[0] == "F":
    x_choku = True
else:
    x_choku = False
# susumu = s.count("F")
# if susumu % 2 != (x + y) % 2:
#     print("No")
#     exit()
# if susumu < (x + y):
#     print("No")
#     exit()
x_houkou = True
cnt = 0
X = []
Y = []
for w in s:
    if w == "F":
        cnt += 1
    else:
        if x_houkou:
            X.append(cnt)
            cnt = 0
            x_houkou = False
        else:
            Y.append(cnt)
            cnt = 0
            x_houkou = True
if cnt > 0:
    if x_houkou:
        X.append(cnt)
    else:
        Y.append(cnt)
if x_choku:
    x -= X[0]
    X = X[1::]


x_ok = False
y_ok = False
if not X:
    if x == 0:
        x_ok = True
    else:
        print("No")
        exit()
if not Y:
    if y == 0:
        y_ok = True
    else:
        print("No")
        exit()

x = abs(x)
y = abs(y)
x_num = len(X)
y_num = len(Y)
if not x_ok:
    dp = [0] * (x + 1)
    dp[0] = 1
    for t in X:
        for i in range(x, -1, -1):
            if dp[i] == 1:
                continue
            if i - t >= 0:
                if dp[i - t] == 1:
                    dp[i] = 1
    x_ok = dp[x]

if not y_ok:
    dp = [0] * (y + 1)
    dp[0] = 1
    for t in Y:
        for i in range(y, -1, -1):
            if dp[i] == 1:
                continue
            if i - t >= 0:
                if dp[i - t] == 1:
                    dp[i] = 1
    y_ok = dp[y]

if x_ok and y_ok:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
if s[0] == "F":
    x_choku = True
else:
    x_choku = False
susumu = s.count("F")
if susumu % 2 != (x + y) % 2:
    print("No")
    exit()
if susumu < (x + y):
    print("No")
    exit()
x_houkou = True
cnt = 0
X = []
Y = []
for w in s:
    if w == "F":
        cnt += 1
    else:
        if x_houkou:
            X.append(cnt)
            cnt = 0
            x_houkou = False
        else:
            Y.append(cnt)
            cnt = 0
            x_houkou = True
if cnt > 0:
    if x_houkou:
        X.append(cnt)
    else:
        Y.append(cnt)
if x_choku:
    x -= X[0]
    X = X[1::]


x_ok = False
y_ok = False
if not X:
    if x == 0:
        x_ok = True
    else:
        print("No")
        exit()
if not Y:
    if y == 0:
        y_ok = True
    else:
        print("No")
        exit()

x = abs(x)
y = abs(y)
x_num = len(X)
y_num = len(Y)
if not x_ok:
    dp = [0] * (x + 1)
    dp[0] = 1
    for t in X:
        for i in range(x, -1, -1):
            if dp[i] == 1:
                continue
            if i - t >= 0:
                if dp[i - t] == 1:
                    dp[i] = 1
    x_ok = dp[x]

if not y_ok:
    dp = [0] * (y + 1)
    dp[0] = 1
    for t in Y:
        for i in range(y, -1, -1):
            if dp[i] == 1:
                continue
            if i - t >= 0:
                if dp[i - t] == 1:
                    dp[i] = 1
    y_ok = dp[y]

if x_ok and y_ok:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
if s[0] == "F":
    x_choku = True
else:
    x_choku = False
susumu = s.count("F")
if susumu % 2 != (x + y) % 2:
    print("No")
    exit()
if susumu < (x + y):
    print("No")
    exit()
x_houkou = True
cnt = 0
X = []
Y = []
for w in s:
    if w == "F":
        cnt += 1
    else:
        if x_houkou:
            X.append(cnt)
            cnt = 0
            x_houkou = False
        else:
            Y.append(cnt)
            cnt = 0
            x_houkou = True
if cnt > 0:
    if x_houkou:
        X.append(cnt)
    else:
        Y.append(cnt)
if x_choku:
    x -= X[0]
    X = X[1::]


x_ok = False
y_ok = False
if not X:
    if x == 0:
        x_ok = True
    else:
        print("No")
        exit()
if not Y:
    if y == 0:
        y_ok = True
    else:
        print("No")
        exit()

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

if not x_ok:
    dp = [[0] * (x + 1) for _ in range(len(X) + 1)]
    dp[0][0] = 1
    for i in range(len(X)):
        ni = i + 1
        for j in range(x + 1):
            nj = j
            dp[ni][nj] += dp[i][j]
            nj = j + X[i]
            if nj <= x:
                dp[ni][nj] += dp[i][j]
    if dp[len(X)][x] > 0:
        x_ok = True

if not y_ok:
    dp = [[0] * (y + 1) for _ in range(len(Y) + 1)]
    dp[0][0] = 1
    for i in range(len(Y)):
        ni = i + 1
        for j in range(y + 1):
            nj = j
            dp[ni][nj] += dp[i][j]
            nj = j + Y[i]
            if nj <= y:
                dp[ni][nj] += dp[i][j]
    if dp[len(Y)][y] > 0:
        y_ok = True

if x_ok and y_ok:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
if s[0] == "F":
    x_choku = True
else:
    x_choku = False
susumu = s.count("F")
if susumu % 2 != (x + y) % 2:
    print("No")
    exit()
if susumu < (x + y):
    print("No")
    exit()
x_houkou = True
cnt = 0
X = []
Y = []
for w in s:
    if w == "F":
        cnt += 1
    else:
        if x_houkou:
            X.append(cnt)
            cnt = 0
            x_houkou = False
        else:
            Y.append(cnt)
            cnt = 0
            x_houkou = True
if cnt > 0:
    if x_houkou:
        X.append(cnt)
    else:
        Y.append(cnt)
if x_choku:
    x -= X[0]
    X = X[1::]


x_ok = False
y_ok = False
if X:
    X.sort()
    x_sum = sum(X)
else:
    x_sum = 0
    if x == 0:
        x_ok = True
    else:
        print("No")
        exit()
if Y:
    Y.sort()
    y_sum = sum(Y)
else:
    y_sum = 0
    if y == 0:
        y_ok = True
    else:
        print("No")
        exit()

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

if not x_ok:
    dpx = [[0] * (x + 1) for _ in range(len(X) + 1)]
    dpx[0][0] = 1
    for i in range(len(X)):
        ni = i + 1
        for j in range(x + 1):
            nj = j
            dpx[ni][nj] += dpx[i][j]
            nj = j + X[i]
            if nj <= x:
                dpx[ni][nj] += dpx[i][j]
    if dpx[len(X)][x] > 0:
        x_ok = True

if not y_ok:
    dpy = [[0] * (y + 1) for _ in range(len(Y) + 1)]
    dpy[0][0] = 1
    for i in range(len(Y)):
        ni = i + 1
        for j in range(y + 1):
            nj = j
            dpy[ni][nj] += dpy[i][j]
            nj = j + Y[i]
            if nj <= y:
                dpy[ni][nj] += dpy[i][j]
    if dpy[len(Y)][y] > 0:
        y_ok = True

if x_ok and y_ok:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

s = input()
x, y = map(int, input().split())
if s[0] == "F":
    x_choku = True
else:
    x_choku = False
susumu = s.count("F")
if susumu % 2 != (x + y) % 2:
    print("No")
    exit()
if susumu < (x + y):
    print("No")
    exit()
x_houkou = True
cnt = 0
X = []
Y = []
for w in s:
    if w == "F":
        cnt += 1
    else:
        if x_houkou:
            X.append(cnt)
            cnt = 0
            x_houkou = False
        else:
            Y.append(cnt)
            cnt = 0
            x_houkou = True
if cnt > 0:
    if x_houkou:
        X.append(cnt)
    else:
        Y.append(cnt)
if x_choku:
    x -= X[0]
    X = X[1::]


x_ok = False
y_ok = False
if X:
    X.sort()
    x_sum = sum(X)
else:
    x_sum = 0
    if x == 0:
        x_ok = True
    else:
        print("No")
        exit()
if Y:
    Y.sort()
    y_sum = sum(Y)
else:
    y_sum = 0
    if y == 0:
        y_ok = True
    else:
        print("No")
        exit()

AX = list(accumulate([0] + X))
AY = list(accumulate([0] + Y))
x = abs(x)
y = abs(y)

if not x_ok:
    dpx = [[0] * (x + 1) for _ in range(len(X) + 1)]
    dpx[0][0] = 1
    for i in range(len(X)):
        ni = i + 1
        for j in range(x + 1):
            nj = j
            dpx[ni][nj] += dpx[i][j]
            nj = j + X[i]
            if nj <= x:
                dpx[ni][nj] += dpx[i][j]
    if dpx[len(X)][x] > 0:
        x_ok = True

if not y_ok:
    dpy = [[0] * (y + 1) for _ in range(len(Y) + 1)]
    dpy[0][0] = 1
    for i in range(len(Y)):
        ni = i + 1
        for j in range(y + 1):
            nj = j
            dpy[ni][nj] += dpy[i][j]
            nj = j + Y[i]
            if nj <= y:
                dpy[ni][nj] += dpy[i][j]
    if dpy[len(Y)][y] > 0:
        y_ok = True

if x_ok and y_ok:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    s=readline().strip()
    x,y=map(int,readline().split())
    n=len(s)

    now_x={0}
    now_y={0}
    i=0
    flag="x"
    cnt=0
    while i<n:
        if s[i]=="F":
            cnt+=1
            i+=1
            if i==n:
                nex=set()
                if flag=="x":
                    l=len(now_x)
                else:
                    l=len(now_y)
                for _ in range(l):
                    if flag=="x":
                        now=now_x.pop()
                    else:
                        now=now_y.pop()
                    nex.add(now+cnt)
                    nex.add(now-cnt)
                if flag=="x":
                    now_x=nex
                    flag="y"
                else:
                    now_y=nex
                    flag="x"
        else:
            nex=set()
            if flag=="x":
                l=len(now_x)
            else:
                l=len(now_y)
            for _ in range(l):
                if flag=="x":
                    now=now_x.pop()
                else:
                    now=now_y.pop()
                nex.add(now+cnt)
                nex.add(now-cnt)
            if flag=="x":
                now_x=nex
                flag="y"
            else:
                now_y=nex
                flag="x"
            i+=1
            cnt=0

    if x in now_x and y in now_y:
        print("Yes")
    else:
        print("No")

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7


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

N = 8010

X = [0]
Y = [0]
flag = True
for s in S:
    if s == 'F':
        if flag:
            X[-1] += 1
        else:
            Y[-1] += 1
    else:
        if flag:
            if Y[-1] != 0:
                Y.append(0)
        else:
            if X[-1] != 0:
                X.append(0)
        flag = not flag

dp = [[0] * (2 * N) for _ in range(2)]
if S[0] == 'F':
    dp[0][X[0] + N] = 1
else:
    dp[0][X[0] + N] = 1
    dp[0][-X[0] + N] = 1

for i in range(1, len(X)):
    x_ = X[i]
    for j in range(2 * N):
        if j >= x_:
            if dp[(i - 1) % 2][j - x_]:
                dp[i % 2][j] = 1
        if j + x_ < 2 * N:
            if dp[(i - 1) % 2][j + x_]:
                dp[i % 2][j] = 1

# print (dp)
if dp[(len(X) - 1) % 2][x + N] == 0:
    print ('No')
    exit()

dp = [[0] * (2 * N) for _ in range(2)]
dp[0][Y[0] + N] = 1
dp[0][-Y[0] + N] = 1

for i in range(1, len(Y)):
    y_ = Y[i]
    for j in range(2 * N):
        if j >= y_:
            if dp[(i - 1) % 2][j - y_]:
                dp[i % 2][j] = 1
        if j + y_ < 2 * N:
            if dp[(i - 1) % 2][j + y_]:
                dp[i % 2][j] = 1

if dp[(len(Y)-1) % 2][y + N] == 0:
    print ('No')
    exit()

print ('Yes')

Submission status: Wrong Answer

Solution code:
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7


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

N = 8010

X = [0]
Y = [0]
flag = True
for s in S:
    if s == 'F':
        if flag:
            X[-1] += 1
        else:
            Y[-1] += 1
    else:
        if flag:
            if Y[-1] != 0:
                Y.append(0)
        else:
            if X[-1] != 0:
                X.append(0)
        flag = not flag

dp = [[0] * (2 * N) for _ in range(2)]
if S[0] == 'F':
    dp[0][X[0] + N] = 1
else:
    dp[0][X[0] + N] = 1
    dp[0][-X[0] + N] = 1

for i in range(1, len(X)):
    x_ = X[i]
    for j in range(2 * N):
        if j >= x_:
            if dp[(i - 1) % 2][j - x_]:
                dp[i % 2][j] = 1
        if j + x_ < 2 * N:
            if dp[(i - 1) % 2][j + x_]:
                dp[i % 2][j] = 1

# print (dp)
if dp[(len(X) - 1) % 2][x + N] == 0:
    print ('No')
    exit()

dp = [[0] * (2 * N) for _ in range(2)]
dp[0][Y[0] + N] = 1
dp[0][-Y[0] + N] = 1

for i in range(1, len(Y)):
    y_ = Y[i]
    for j in range(2 * N):
        if j >= y_:
            if dp[(i - 1) % 2][j - y_]:
                dp[i % 2][j] = 1
        if j + y_ < 2 * N:
            if dp[(i - 1) % 2][j + y_]:
                dp[i % 2][j] = 1

if dp[(N-1) % 2][y + N] == 0:
    print ('No')
    exit()

print ('Yes')

Submission status: Wrong Answer

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    s=readline().strip()
    x,y=map(int,readline().split())
    n=len(s)
    c=8003
    d=16006

    cnt_t=s.count("T")
    if cnt_t%2==0:
        cnt_x=cnt_t//2+1
        cnt_y=cnt_t//2
    else:
        cnt_x=cnt_t//2+1
        cnt_y=cnt_t//2+1
    dpx=[[False]*d for _ in range(cnt_x+1)]
    dpy=[[False]*d for _ in range(cnt_y+1)]
    dpx[0][0+c]=True
    dpy[0][0+c]=True
    flag="x"
    i=0
    cnt_f=0
    now_x=0
    now_y=0
    while i<n:
        if s[i]=="F":
            cnt_f+=1
            i+=1
            if i==n:
                if flag=="x":
                    for j in range(d):
                        if dpx[now_x][j]:
                            dpx[now_x+1][j+cnt_f]=True
                            dpx[now_x+1][j-cnt_f]=True
                    flag="y"
                    now_x+=1
                    cnt_f=0
                    i+=1
                elif flag=="y":
                    for j in range(d):
                        if dpy[now_y][j]:
                            dpy[now_y+1][j+cnt_f]=True
                            dpy[now_y+1][j-cnt_f]=True
                    flag="x"
                    cnt_f=0
                    now_y+=1
                    i+=1
        else:
            if flag=="x":
                for j in range(d):
                    if dpx[now_x][j]:
                        dpx[now_x+1][j+cnt_f]=True
                        dpx[now_x+1][j-cnt_f]=True
                flag="y"
                now_x+=1
                cnt_f=0
                i+=1
            elif flag=="y":
                for j in range(d):
                    if dpy[now_y][j]:
                        dpy[now_y+1][j+cnt_f]=True
                        dpy[now_y+1][j-cnt_f]=True
                flag="x"
                cnt_f=0
                now_y+=1
                i+=1

    if dpx[now_x][x+c] and dpy[now_y][y+c]:
        print("Yes")
    else:
        print("No")

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
S=input()
x,y=map(int, input().split())
N=len(S)
now=0
xs=[]
ys=[]
count=0
for i in range(N):
    if S[i]=="F":
        now+=1
    else:
        if count%2==0:
            xs.append(now)
        else:
            ys.append(now)
        count+=1
        now=0
    if S[i]=="F" and i==N-1:
        if count%2==0:
            xs.append(now)
        else:
            ys.append(now)
print(xs,ys)
from collections import defaultdict
D=defaultdict(int)

xnow=xs.pop(0)
D[xnow]=1
for i in range(len(xs)):
    dx=xs[i]
    ds=D.keys()
    D=defaultdict(int)
    for v in ds:
        D[v+dx]=1
        D[v-dx]=1
D=dict(D)
#print(D)
xok=x in D


D=defaultdict(int)
D[0]=1
for i in range(len(ys)):
    dy=ys[i]
    ds=D.keys()
    D=defaultdict(int)
    for v in ds:
        D[v+dy]=1
        D[v-dy]=1
D=dict(D)
#print(D)
yok=y in D


if xok and yok:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

s = input()
x, y = map(int, input().split())
if s[0] == "F":
    x_choku = True
else:
    x_choku = False
susumu = s.count("F")
if susumu % 2 != (x + y) % 2:
    print("No")
    exit()
if susumu < (x + y):
    print("No")
    exit()
x_houkou = True
cnt = 0
X = []
Y = []
for w in s:
    if w == "F":
        cnt += 1
    else:
        if x_houkou:
            X.append(cnt)
            cnt = 0
            x_houkou = False
        else:
            Y.append(cnt)
            cnt = 0
            x_houkou = True
if cnt > 0:
    if x_houkou:
        X.append(cnt)
    else:
        Y.append(cnt)
if x_choku:
    x -= X[0]
    X = X[1::]


x_ok = False
y_ok = False
if X:
    X.sort()
    x_sum = sum(X)
else:
    x_sum = 0
    if x == 0:
        x_ok = True
    else:
        print("No")
        exit()
if Y:
    Y.sort()
    y_sum = sum(Y)
else:
    y_sum = 0
    if y == 0:
        y_ok = True
    else:
        print("No")
        exit()

AX = list(accumulate([0] + X))
AY = list(accumulate([0] + Y))
x = abs(x)
y = abs(y)
if not x_ok:
    for i in range(len(X) + 1):
        temp = x_sum - 2 * AX[i]
        if x == temp:
            x_ok = True
            break
if not y_ok:
    for i in range(len(Y) + 1):
        temp = y_sum - 2 * (AY[i])
        if y == temp:
            y_ok = True
            break
if x_ok and y_ok:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
S = input().split('T')

N = len(S)
X = []
Y = []

for i in range(N):
    if i%2:
        Y.append(len(S[i]))
    else:
        X.append(len(S[i]))

Xsum = sum(X)
Ysum = sum(Y)

from collections import defaultdict

dpx = defaultdict(int)# 初期値を0にした辞書
dpy = defaultdict(int)# 初期値を0にした辞書

dpx[Xsum] = 1
dpy[Ysum] = 1

for x in X:
    for i in range(-Xsum,Xsum+1):
        if dpx[i]:
            dpx[i-2*x] = 1

for y in Y:
    for i in range(-Ysum,Ysum+1):
        if dpy[i]:
            dpy[i-2*y] = 1

x,y = map(int,input().split())
print('Yes' if dpx[x] and dpy[y] else 'No')

Submission status: Wrong Answer

Solution code:
S = input().split('T')

N = len(S)
X = []
Y = []

for i in range(N):
    if i%2:
        Y.append(len(S[i]))
    else:
        X.append(len(S[i]))

Xsum = sum(X)
Ysum = sum(Y)

from collections import defaultdict

dpx = defaultdict(int)# 初期値を0にした辞書
dpy = defaultdict(int)# 初期値を0にした辞書

dpx[Xsum] = 1
dpy[Ysum] = 1

for x in X:
    for i in range(-Xsum+2*x,Xsum+1):
        if dpx[i]:
            dpx[i-2*x] = 1

for y in Y:
    for i in range(-Ysum+2*y,Ysum+1):
        if dpy[i]:
            dpy[i-2*y] = 1

x,y = map(int,input().split())
print('Yes' if dpx[x] and dpy[y] else 'No')

Submission status: Wrong Answer

Solution code:
s = input().split('T')
s = [len(_s) for _s in s]
x, y = map(int, input().split())
dx = s[::2]
dy = [0]+s[1::2]

def check(dz, z, base=8001, first_fixed=True):
  a = dz[0]
  if first_fixed:
    state = 1 << base + a
  else:
    state = 1 << (base + a) | 1 << (base - a) 
  for a in dz[1:]:
    state |= (state<<a | state>>a)
  return (state>>(base+z)) & 1

if check(dx, x) and check(dy, y, first_fixed=False):
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

ini = [0,0]
drc = [1,0]

for i in range(len(s)):
    if s[i] == 'F':
        for j in range(2):
            ini[j] = drc[j]+ini[j]
    else:
        x_d = x - ini[0]
        y_d = y - ini[1]
        if drc == [1,0] or drc == [-1,0]:
            if y_d >= 0:
                drc = [0,1]
            else:
                drc = [0,-1]
        else:
            if x_d >= 0:
                drc = [1,0]
            else:
                drc = [-1,0]
            
X,Y = ini

if x == X and y == Y:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
x, y = map(int, input().split())
if set(s) == {'F'}:
    if x == len(s) and y == 0:
        print('Yes')
    else:
        print('No')
    exit()
        
dx = []
dy = []
xy = 0
cnt =0
for i in s:
    if i == 'F':
        cnt += 1
    else:
        xy += 1
        xy %= 2
        if xy:
            dx.append(cnt)
        else:
            dy.append(cnt)
        cnt = 0
if cnt != 0:
    if xy:
        dy.append(cnt)
    else:
        dx.append(cnt)
dpx = [[0] * n for i in range(len(dx))]
dpy = [[0] * n for i in range(len(dy))]

if dx:
    dpx[0][dx[0]] = True
if dy:
    dpy[0][dy[0]] = True
    dpy[0][-dy[0]] = True
for i in range(1, len(dx)):
    for j in range(0, n):
        dpx[i][j] = dpx[i-1][j-dx[i]] or dpx[i-1][(j+dx[i])%n]
for i in range(1, len(dy)):
    for j in range(0, n):
        dpy[i][j] = dpy[i-1][j-dy[i]] or dpy[i-1][(j+dy[i])%n]
print('Yes' if dpx[-1][x] and dpy[-1][y] else 'No')

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
cnt = [0, 0]
angle = 0
for i in s:
    if i == 'T':
        angle += 1
        angle %= 2
    else:
        cnt[angle%2==1] += 1
print('Yes' if abs(x) <= cnt[0] and abs(y) <= cnt[1] and x%2 == cnt[0]%2 and y%2 == cnt[1]%2 else 'No')