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:
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy

def solve():
    s = getS()
    x, y = getList()
    ls = len(s)
    hori = True
    h,v = [],[]
    cnt = 0
    for c in s:
        if c == "F":
            cnt += 1
        else:
            if hori:
                h.append(cnt)
            else:
                v.append(cnt)
            cnt = 0
            hori = not hori

    if cnt != 0:
        if hori:
            h.append(cnt)
        else:
            v.append(cnt)

    # print(h, v)
    dp = [0 for i in range(-ls - 100, ls + 100)]
    dp[ls + 100] = 1
    for num in h:
        tmp = copy.copy(dp)
        for i, d in enumerate(dp):
            if d == 1:
                if i - num >= 0:
                    tmp[i - num] = 1
                if i + num < len(dp):
                    tmp[i + num] = 1
        dp = tmp
    if dp[x] == 0:
        print("No")
        return

    dp = [0 for i in range(-ls - 100, ls + 100)]
    dp[ls+100] = 1
    for num in v:
        tmp = copy.copy(dp)
        for i, d in enumerate(dp):
            if d == 1:
                if i - num >= 0:
                    tmp[i - num] = 1
                if i + num < len(dp):
                    tmp[i + num] = 1
        dp = tmp
        # print(dp)
    if dp[y] == 0:
        print("No")
        return
    # print(dp)
    print("Yes")
    return


def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Wrong Answer

Solution code:
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy

def solve():
    s = getS()
    x, y = getList()
    ls = len(s)
    hori = True
    h,v = [],[]
    cnt = 0
    for c in s:
        if c == "F":
            cnt += 1
        else:
            if hori:
                h.append(cnt)
            else:
                v.append(cnt)
            cnt = 0
            hori = not hori

    if cnt != 0:
        if hori:
            h.append(cnt)
        else:
            v.append(cnt)

    # print(h, v)

    dp = [0 for i in range(-ls - 100, ls + 100)]
    dp[0] = 1
    for num in h:
        for i, d in enumerate(dp):
            if d == 1:
                if i - num > -ls - 50:
                    dp[i - num] = 1
                if i + num < ls + 50:
                    dp[i + num] = 1

    if dp[x] == 0:
        print("No")
        return

    dp = [0 for i in range(-ls - 100, ls + 100)]
    dp[0] = 1
    for num in v:
        for i, d in enumerate(dp):
            if d == 1:
                if i - num > -ls - 50:
                    dp[i - num] = 1
                if i + num < ls + 50:
                    dp[i + num] = 1

    if dp[y] == 0:
        print("No")
        return

    print("Yes")
    return


def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Wrong Answer

Solution code:
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy

def solve():
    s = getS()
    x, y = getList()
    ls = len(s)
    hori = True
    h,v = [],[]
    cnt = 0
    for c in s:
        if c == "F":
            cnt += 1
        else:
            if hori:
                h.append(cnt)
            else:
                v.append(cnt)
            cnt = 0
            hori = not hori

    if cnt != 0:
        if hori:
            h.append(cnt)
        else:
            v.append(cnt)

    # print(h, v)

    dp = [0 for i in range(-ls - 2, ls + 2)]
    dp[0] = 1
    for num in h:
        for i, d in enumerate(dp):
            if d == 1:
                if i - num > -ls - 1:
                    dp[i - num] = 1
                if i + num < ls + 1:
                    dp[i + num] = 1

    if dp[x] == 0:
        print("No")
        return

    dp = [0 for i in range(-ls - 2, ls + 2)]
    dp[0] = 1
    for num in v:
        for i, d in enumerate(dp):
            if d == 1:
                if i - num > -ls - 1:
                    dp[i - num] = 1
                if i + num < ls + 1:
                    dp[i + num] = 1

    if dp[y] == 0:
        print("No")
        return

    print("Yes")
    return


def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Wrong Answer

Solution code:
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    s = input()
#    s = "FT"*4000
    x,y = map(int,ipt().split())
#    x = 2000
#    y = 2000

    move = [[],[]]
    p = 0
    nm = 0
    for i in s:
        if i == "T":
            move[p].append(nm)
            nm = 0
            p = 1-p
        else:
            nm += 1
    move[p].append(nm)

    st = set([0])
    for i in move[0]:
        nst = set()
        for j in st:
            nst.add(j+i)
            nst.add(j-i)
        st = nst.copy()
    if not x in st:
        print("No")
        exit()

    st = set([0])
    for i in move[1]:
        nst = set()
        for j in st:
            nst.add(j+i)
            nst.add(j-i)
        st = nst.copy()
    if not y in st:
        print("No")
        exit()

    print("Yes")

    return None

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    S = input()
    X, Y = map(int, input().split())

    init_x = 0
    x = y = 0
    flg = 0
    to_x = 1
    for s in S:
        if s == "F":
            if not flg:
                init_x += 1
            else:
                if to_x:
                    x += 1
                else:
                    y += 1
        else:
            to_x ^= 1
            flg = 1

    now_x = {init_x}
    for i in range(x):
        tmp = set()
        for now in now_x:
            tmp.add(now - 1)
            tmp.add(now + 1)
        now_x = tmp

    now_y = {0}
    for i in range(y):
        tmp = set()
        for now in now_y:
            tmp.add(now - 1)
            tmp.add(now + 1)
        now_y = tmp

    print("Yes" if X in now_x and Y in now_y else "No")


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    S = input()
    X, Y = map(int, input().split())

    x = y = 0
    flg = 1
    for s in S:
        if s == "F":
            if flg:
                x += 1
            else:
                y += 1
        else:
            flg ^= 1

    dp_x = [set() for _ in range(x + 1)]
    dp_x[0].add(0)
    for i in range(1, x + 1):
        for now in dp_x[i - 1]:
            dp_x[i].add(now - 1)
            dp_x[i].add(now + 1)

    dp_y = [set() for _ in range(y + 1)]
    dp_y[0].add(0)
    for i in range(1, y + 1):
        for now in dp_y[i - 1]:
            dp_y[i].add(now - 1)
            dp_y[i].add(now + 1)

    print("Yes" if X in dp_x[-1] and Y in dp_y[-1] else "No")


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    S = input()
    X, Y = map(int, input().split())
    MAX = 8000 * 2 + 10

    x = y = 0
    flg = 1
    for s in S:
        if s == "F":
            if flg:
                x += 1
            else:
                y += 1
        else:
            flg ^= 1

    dp_x = [[False] * MAX for _ in range(x + 1)]
    dp_x[0][MAX // 2] = True
    for i in range(1, x + 1):
        for j in range(MAX):
            if dp_x[i - 1][j]:
                dp_x[i][j - 1] = True
                dp_x[i][j + 1] = True

    dp_y = [[False] * MAX for _ in range(y + 1)]
    dp_y[0][MAX // 2] = True
    for i in range(1, y + 1):
        for j in range(MAX):
            if dp_y[i - 1][j]:
                dp_y[i][j - 1] = True
                dp_y[i][j + 1] = True

    print("Yes" if dp_x[-1][MAX // 2 + X] and dp_y[-1][MAX // 2 + Y] else "No")


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    S = input()
    X, Y = map(int, input().split())
    MAX = 16000 * 2 + 10

    x = y = 0
    flg = 1
    for s in S:
        if s == "F":
            if flg:
                x += 1
            else:
                y += 1
        else:
            flg ^= 1

    dp_x = [0] * MAX
    dp_x[MAX // 2] = 1
    for i in range(x):
        j = 0
        while j < MAX:
            if dp_x[j] == 1:
                dp_x[j] = 0
                dp_x[j - 1] = 1
                dp_x[j + 1] = 1
                j += 2
            else:
                j += 1

    dp_y = [0] * MAX
    dp_y[MAX // 2] = 1
    for i in range(y):
        j = 0
        while j < MAX:
            if dp_y[j] == 1:
                dp_y[j] = 0
                dp_y[j - 1] = 1
                dp_y[j + 1] = 1
                j += 2
            else:
                j += 1

    print("Yes" if dp_x[MAX // 2 + X] and dp_y[MAX // 2 + Y] else "No")


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	s=input().rstrip().decode()+"T"
	x,y=MI()
	X=[]
	Y=[]

	i=0

	if s[0]=="F":
		for ss in s:
			if ss=="F":
				x-=1
				i+=1
			else:
				break
	#print(x,y,i)

	while True:
		ii=s.find("T",i+1)
		if ii==-1:
			break
		Y.append(ii-i-1)

		i=s.find("T",ii+1)
		if i==-1:
			break
		X.append(i-ii-1)
	#print(X,Y)


	s=set([0])
	ss=set()
	for i in X:
		for j in s:
			ss.add(j+i)
			ss.add(j-i)
		s=ss.copy()
	#print(s)

	if x not in s:
		print("No")
		exit()

	s=set([0])
	ss=set()
	for i in Y:
		for j in s:
			ss.add(j+i)
			ss.add(j-i)
		s=ss.copy()
	#print(s)

	if y not in s:
		print("No")
		exit()

	print("Yes")






















if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
s = list(input())
x, y = map(int, input().split())
a = [0, 0]
j = 0
for i in s:
    if i == "F":
        if j == 0:
            x -= 1
        else:
            a[j % 2] += 1
    else:
        j += 1
x, y = abs(x), abs(y)
print("Yes" if (a[0] - x) % 2 == (a[1] - y) % 2 == 0 and a[0] >= x and a[1] >= y else "No")

Submission status: Wrong Answer

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

def isinsums(x,lst):
  s=sum(lst)
  t=(s+x)//2
  if s==0 and x==0:
    return True
  if (s-x)%2 or t<0:
    return False
  t=(s+x)//2
  m1=1<<(t+1)-1
  m2=1<<t
  sums=0
  for e in lst:
    sms=(sums|(1+sums)<<e)&m1
    if (sms|1)&m2>0:
      return True
  return False

s=readline().strip()
x,y=map(int,readline().split())

s=s.replace('TF','T F')
s=s.replace('FT','F T')
bs=s.split()
if bs[0][0]=='F':
  x-=len(bs[0])
  del bs[0]

xy=[[],[]]
f=0
for i,e in enumerate(bs):
  if not i%2:
    l=len(e)
  else:
    f^=l%2
    xy[f].append(len(e))
if isinsums(x,xy[0]) and isinsums(y,xy[1]):
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

def isinsums(x,lst):
  s=sum(lst)
  t=(s+x)//2
  if s==0 and x==0:
    return True
  if (s-x)%2 or t<0:
    return False
  t=(s+x)//2
  m1=1<<(t+1)-1
  m2=1<<t
  sums=0
  for e in lst:
    sms=(sums|(1+sums)<<e)&m1
    if (sms|1)&m2>0:
      return True
  return False

s=readline().strip()
x,y=map(int,readline().split())

s=s.replace('TF','T F')
s=s.replace('FT','F T')
bs=s.split()
if bs[0][0]=='F':
  x-=len(bs[0])
  del bs[0]

xy=[[],[]]
f=0
for i,e in enumerate(bs):
  if not i%2:
    l=len(e)
  else:
    f^=l%2
    xy[f].append(len(e))
print(bs,xy,x,y)
if isinsums(x,xy[0]) and isinsums(y,xy[1]):
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def check(vec, init_pos, target_pos):
    dp = {init_pos}

    for nv in vec:
        dp_next = set()
        for v in dp:
            dp_next.add(v - nv)
            dp_next.add(v + nv)
        dp = dp | dp_next

    return target_pos in dp


def main():
    S = readline().strip()
    x, y = map(int, readline().split())

    L = [len(commands) for commands in S.split('T')]

    init_x = L[0]
    x_commands = L[2::2]
    y_commands = L[1::2]

    ok = check(x_commands, init_x, x) and check(y_commands, 0, y)

    if ok:
        print('Yes')
    else:
        print('No')

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def check(vec, init_pos, target_pos):
    dp = {init_pos}

    for nv in vec:
        dp_next = set()
        for v in dp:
            dp_next.add(v - nv)
            dp_next.add(v + nv)
        dp = dp | dp_next

    return target_pos in dp


def main():
    S = readline().strip()
    x, y = map(int, readline().split())

    idx = len(S)
    for i, c in enumerate(S):
        if c == 'T':
            idx = i
            break

    init_x = idx
    step = [[] for _ in range(2)]
    i = 0
    for c in S[idx:]:
        if c == 'T':
            i = 1 - i
            step[i].append(0)
        else:
            step[i][-1] += 1

    for row in step:
        row = [v for v in row if v != 0]
        if not row:
            row = [0]

    ok = check(step[0], init_x, x) and check(step[1], 0, y)

    if ok:
        print('Yes')
    else:
        print('No')

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    x, y = map(int, readline().split())

    idx = len(S)
    for i, c in enumerate(S):
        if c == 'T':
            idx = i
            break

    init_x = idx
    step = [0] * 2
    i = 0
    for c in S[idx:]:
        if c == 'T':
            i = 1 - i
        else:
            step[i] += 1

    if (
        step[0] >= abs(x - init_x)
        and (step[0] - abs(x - init_x)) % 2 == 0
        and step[1] >= abs(y)
        and (step[1] - abs(y)) % 2 == 0
    ):
        print('Yes')
    else:
        print('No')

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from copy import copy
s = input()
n=len(s)
x, y = map(int, input().split())

d = [len(v) for v in s.split("T")]
x -= d[0]
a = d[2::2]
b = d[1::2]


def c(d, x):
    cur = {0}
    for i in d:
        nxt = set()
        for j in cur:
            nxt.add(j + i)
            nxt.add(j - i)
        cur = copy(nxt)
    return x in d

print("Yes" if c(a, x) and c(b, y) else "No")

Submission status: Wrong Answer

Solution code:
def turn():
  global drc
  if moves[drc][-1] != 0:
    moves[drc].append(0)
  drc=(drc+1)%2

def forward():
  moves[drc][-1]+=1
  
OP={"T":turn,"F":forward}

ops=input()
target=list(map(int,input().split()))
moves=[[0],[0]]
drc=0
first_F=0

# データ加工
for i,o in enumerate(ops):
  if o=="T":
    first_F=i
    break

for i in range(first_F,len(ops)):
  OP[ops[i]]()

# 組み合わせ演算
x_set=set([first_F])
for move in moves[0]:
  tmp_set=set()
  for xx in x_set:
    tmp_set.add(xx+move)
    tmp_set.add(xx-move)
  x_set=tmp_set
  
y_set=set([0])
for move in moves[1]:
  tmp_set=set()
  for yy in y_set:
    tmp_set.add(yy+move)
    tmp_set.add(yy-move)
  y_set=tmp_set

if target[0] in x_set and target[1] in y_set:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
def turn():
  global drc
  drc=(drc+1)%2

def forward():
  if pos[drc] > target[drc]:
    pos[drc]-=1
  else:
    pos[drc]+=1
  
OP={"T":turn,"F":forward}
pos=[0,0]
target=[0,0]
drc=0

ops=input()
pos[0],pos[1]=map(lambda x:abs(int(x)),input().split())

for o in ops:
  OP[o]()
ans = "Yes" if pos == target else "No"
print(ans)

Submission status: Wrong Answer

Solution code:
def turn():
  global drc
  drc=(drc+1)%2

def forward():
  if pos[drc] > target[drc]:
    pos[drc]-=1
  else:
    pos[drc]+=1
  
OP={"T":turn,"F":forward}
pos=[0,0]
target=[0,0]
drc=0

ops=input()
pos[0],pos[1]=map(int,input().split())

for o in ops:
  OP[o]()
ans = "Yes" if pos == target else "No"
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int, input().split())
cx=[]
cy=[]
dirx=1
l=0
ini=1
for i in range(len(s)):
  if s[i] == "F":
    l += 1
  else:
    if ini:
      x -= l
      ini = 0
    else:
      if dirx:
        cx.append(l)
      else:
        cy.append(l)
    l = 0
    dirx = not dirx

if ini == 0:
  if dirx:
    cx.append(l)
  else:
    cy.append(l)

#print(cx)
#print(cy)


ng = 0
dp = {0}
for i in range( len(cx) ):
  dpn = set()
  for d in dp:
    dpn.add(d+cx[i])
    dpn.add(d-cx[i])
#  print(dpn)
  dpn, dp = dp, dpn
  
if not x in dp:
  ng = 1
#  print(x, dp[x])
  
dp = {0}
for i in range( len(cy) ):
  dpn = set()
  for d in dp:
    dpn.add(d+cy[i])
    dpn.add(d-cy[i])
#  print(dpn)
  dpn, dp = dp, dpn
  
if not y in dp:
  ng = 1
#  print(y, dp[y])

if ng==0:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int, input().split())
x += 9000
y += 9000
cx=[]
cy=[]
dirx=1
l=0
ini=1
for i in range(len(s)):
  if s[i] == "F":
    l += 1
  else:
    if ini:
      x -= l
      ini = 0
    else:
      if dirx:
        cx.append(l)
      else:
        cy.append(l)
    l = 0
    dirx = not dirx

if ini == 0:
  if dirx:
    cx.append(l)
  else:
    cy.append(l)

#print(cx)
#print(cy)


ng = 0
dp = [0 for i in range(18000)] 
dpn = [0 for i in range(18000)] 
dp[9000] = 1;
for i in range( len(cx) ):
  for j in range( 18000 ):
    if dp[j]:
      if j+cx[i] < 18000:
        dpn[j+cx[i]] = 1;
        if j-cx[i] > 0:
          dpn[j-cx[i]] = 1;
      dp[j] = 0
#  for j in range( 8995,9005 ):
#    print( str(dpn[j])+" ", end="")
#  print("")
  dpn, dp = dp, dpn
  
if dp[x] == 0:
  ng = 1
#  print(x, dp[x])
  
dp = [0 for i in range(18000)] 
dpn = [0 for i in range(18000)] 
dp[9000] = 1;
for i in range( len(cy) ):
  for j in range( 18000 ):
    if dp[j]:
      if j+cy[i] < 18000:
        dpn[j+cy[i]] = 1;
        if j-cy[i] > 0:
          dpn[j-cy[i]] = 1;
      dp[j] = 0
#  for j in range( 8995,9005 ):
#   print( str(dpn[j])+" ", end="")
#  print("")
  dpn, dp = dp, dpn
  
if dp[y] == 0:
  ng = 1
#  print(y, dp[y])

if ng==0:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int, input().split())
x += 9000
y += 9000
cx=[]
cy=[]
dirx=1
l=0
ini=1
for i in range(len(s)):
  if s[i] == "F":
    l += 1
  else:
    if ini:
      x -= l
      ini = 0
    else:
      if dirx:
        cx.append(l)
      else:
        cy.append(l)
    l = 0
    dirx = not dirx

if ini == 0:
  if dirx:
    cx.append(l)
  else:
    cy.append(l)

#print(cx)
#print(cy)


ng = 0
dp = [0 for i in range(18000)] 
dpn = [0 for i in range(18000)] 
dp[9000] = 1;
for i in range( len(cx) ):
  for j in range( 18000 ):
    if j+cx[i] < 18000:
      dpn[j+cx[i]] |= dp[j]
    if j-cx[i] > 0:
      dpn[j-cx[i]] |= dp[j]
    dp[j] = 0
#  for j in range( 8995,9005 ):
#    print( str(dpn[j])+" ", end="")
#  print("")
  dpn, dp = dp, dpn
  
if dp[x] == 0:
  ng = 1
  print(x, dp[x])
  
dp = [0 for i in range(18000)] 
dpn = [0 for i in range(18000)] 
dp[9000] = 1;
for i in range( len(cy) ):
  for j in range( 18000 ):
    if j+cy[i] < 18000:
      dpn[j+cy[i]] |= dp[j]
    if j-cy[i] > 0:
      dpn[j-cy[i]] |= dp[j]
    dp[j] = 0
#  for j in range( 8995,9005 ):
#   print( str(dpn[j])+" ", end="")
#  print("")
  dpn, dp = dp, dpn
  
if dp[y] == 0:
  ng = 1
  print(y, dp[y])

if ng==0:
  print("Yes")
else:
  print("No")