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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

S = S()
gx,gy = IL()

data = [0]
flag = 0
for s in S:
  if s == "F":
    if flag:
      flag = 0
      data.append(1)
    else:
      data[-1] = data[-1]+1
  else:
    if flag == 0:
      flag = 1
      data.append(1)
    else:
      data[-1] = 1-data[-1]

if len(data)%2 == 0:
  data.pop()
data = data[::-1]
shote = data.pop()
gx -= shote
D = [[0],[0]]
f = 0


while data:
  f ^= data.pop()
  D[f].append(data.pop())
SUMX = sum(D[0])
SUMY = sum(D[1])
dpx =  [[0 for i in range(SUMX*2+1)] for j in range(len(D[0]))]
dpy =  [[0 for i in range(SUMY*2+1)] for j in range(len(D[1]))]
dpx[0][SUMX] = 1
dpy[0][SUMY] = 1
for j in range(1,len(D[0])):
  d = D[0][j]
  for i in range(SUMX):
    if i+d < SUMX:
      if dpx[j-1][i+d]:
        dpx[j][i] = 1
    if 0 <= i-j:
      if dpx[j-1][i-d]:
        dpx[j][i] = 1
for j in range(1,len(D[1])):
  d = D[1][j]
  for i in range(SUMY):
    if i+d < SUMY:
      if dpy[j-1][i+d]:
        dpy[j][i] = 1
    if 0 <= i-j:
      if dpy[j-1][i-d]:
        dpy[j][i] = 1
if (0<= SUMX+gx < SUMX*2+1) and (0<= SUMY+gy < SUMY*2+1):
  if dpx[-1][SUMX+gx] and dpy[-1][SUMY+gy]: 
    print("Yes")
    exit()
print("No")

Submission status: Wrong Answer

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

f = s.find('T')
if f >= 0:
    x = abs(x - f)
    s = s[f:]
else:
    if x == len(s) - 1 and y == 0:
        print('Yes')
    else:
        print('No')
    exit()

lx, ly = [], []
flag = True
n = 0
s += 'T'
for i in s:
    if i == 'F':
        n += 1
    else:
        if n > 0:
            if flag:
                lx.append(n)
            else:
                ly.append(n)
            n = 0
        flag = not flag

lx.sort()
ly.sort()
sx = sum(lx)
sy = sum(ly)

if sx < x or (sx - x) % 2 == 1 or sy < y or (sy - y) % 2 == 1:
    print('No')
    exit()


def main(x, sx, lx):
    if x == sx:
        return True

    goal = (sx - x) // 2
    # return (sum of some lx == goal)
    dp = [False] * (goal + 1)
    dp[0] = True
    for i in lx:
        if i > goal:
            return False
        for j in range(goal - i, -1, -1):
            if dp[j]:
                dp[j+i] = True
        if dp[goal]:
            return True
    return False


if main(x, sx, lx) and main(y, sy, ly):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

f = s.find('T')
if f >= 0:
    x = abs(x - f)
    s = s[f:]
else:
    x = abs(x)

lx, ly = [], []
flag = True
n = 0
s += 'T'
for i in s:
    if i == 'F':
        n += 1
    else:
        if n > 0:
            if flag:
                lx.append(n)
            else:
                ly.append(n)
            n = 0
        flag = not flag

lx.sort()
ly.sort()
sx = sum(lx)
sy = sum(ly)

if sx < x or (sx - x) % 2 == 1 or sy < y or (sy - y) % 2 == 1:
    print('No')
    exit()


def main(x, sx, lx):
    if x == sx:
        return True

    goal = (sx - x) // 2
    # return (sum of some lx == goal)
    dp = [False] * (goal + 1)
    dp[0] = True
    for i in lx:
        if i > goal:
            return False
        for j in range(goal - i, -1, -1):
            if dp[j]:
                dp[j+i] = True
        if dp[goal]:
            return True
    return False


if main(x, sx, lx) and main(y, sy, ly):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

f = s.find('T')
if f >= 0:
    x = abs(x - f)
    s = s[f:]

lx, ly = [], []
flag = True
n = 0
s += 'T'
for i in s:
    if i == 'F':
        n += 1
    else:
        if n > 0:
            if flag:
                lx.append(n)
            else:
                ly.append(n)
            n = 0
        flag = not flag

lx.sort()
ly.sort()
sx = sum(lx)
sy = sum(ly)

if sx < x or (sx - x) % 2 == 1 or sy < y or (sy - y) % 2 == 1:
    print('No')
    exit()


def main(x, sx, lx):
    if x == sx:
        return True

    goal = (sx - x) // 2
    # return (sum of some lx == goal)
    dp = [False] * (goal + 1)
    dp[0] = True
    for i in lx:
        if i > goal:
            return False
        for j in range(goal - i, -1, -1):
            if dp[j]:
                dp[j+i] = True
        if dp[goal]:
            return True
    return False


if main(x, sx, lx) and main(y, sy, ly):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

lx, ly = [], []
flag = True
n = 0
s += 'T'
for i in s:
    if i == 'F':
        n += 1
    else:
        if n > 0:
            if flag:
                lx.append(n)
            else:
                ly.append(n)
            n = 0
        flag = not flag

if lx != []:
    x = abs(x - lx.pop(0))

lx.sort()
ly.sort()
sx = sum(lx)
sy = sum(ly)

if sx < x or (sx - x) % 2 == 1 or sy < y or (sy - y) % 2 == 1:
    print('No')
    exit()


def main(x, sx, lx):
    if x == sx:
        return True

    goal = (sx - x) // 2
    # return (sum of some lx == goal)
    dp = [False] * (goal + 1)
    dp[0] = True
    for i in lx:
        if i > goal:
            return False
        for j in range(goal - i, -1, -1):
            if dp[j]:
                dp[j+i] = True
        if dp[goal]:
            return True
    return False


if main(x, sx, lx) and main(y, sy, ly):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

lx, ly = [], []
flag = True
n = 0
s += 'T'
for i in s:
    if i == 'F':
        n += 1
    else:
        if n > 0:
            if flag:
                lx.append(n)
            else:
                ly.append(n)
            n = 0
        flag = not flag

lx.sort()
ly.sort()
sx = sum(lx)
sy = sum(ly)

if sx < x or (sx - x) % 2 == 1 or sy < y or (sy - y) % 2 == 1:
    print('No')
    exit()


def main(x, sx, lx):
    if x == sx:
        return False

    goal = (sx - x) // 2
    # return (sum of some lx == goal)
    dp = [False] * (goal + 1)
    dp[0] = True
    for i in lx:
        if i > goal:
            return False
        for j in range(goal - i, -1, -1):
            if dp[j]:
                dp[j+i] = True
        if dp[goal]:
            return True
    return False


if main(x, sx, lx) and main(y, sy, ly):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

lx, ly = [], []
flag = True
n = 0
s += 'T'
for i in s:
    if i == 'F':
        n += 1
    else:
        if n > 0:
            if flag:
                lx.append(n)
            else:
                ly.append(n)
            n = 0
        flag = not flag

lx.sort()
ly.sort()
sx = sum(lx)
sy = sum(ly)

if sx < x or (sx - x) % 2 == 1 or sy < y or (sy - y) % 2 == 1:
    print('No')
    exit()


def main(x, sx, lx):
    if x == sx:
        return True

    goal = (sx - x) // 2
    # return (sum of some lx == goal)
    dp = [False] * (goal + 1)
    dp[0] = True
    for i in lx:
        if i > goal:
            return False
        for j in range(goal - i, -1, -1):
            if dp[j]:
                dp[j+i] = True
        if dp[goal]:
            return True
    return False


if main(x, sx, lx) and main(y, sy, ly):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

lx, ly = [], []
flag = True
n = 0
s += 'T'
for i in s:
    if i == 'F':
        n += 1
    else:
        if n > 0:
            if flag:
                lx.append(n)
            else:
                ly.append(n)
            n = 0
        flag = not flag

lx.sort()
ly.sort()
sx = sum(lx)
sy = sum(ly)

if sx < x or (sx - x) % 2 == 1 or sy < y or (sy - y) % 2 == 1:
    print('No')
    exit()


def main(x, sx, lx):
    goal = (sx - x) // 2
    if goal == 0:
        return False
    
    # return (sum of some lx == goal)
    dp = [False] * (goal + 1)
    dp[0] = True
    for i in lx:
        if i > goal:
            return False
        for j in range(goal - i, -1, -1):
            if dp[j]:
                dp[j+i] = True
        if dp[goal]:
            return True
    return False


if main(x, sx, lx) and main(y, sy, ly):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

lx, ly = [], []
flag = True
n = 0
s += 'T'
for i in s:
    if i == 'F':
        n += 1
    else:
        if n > 0:
            if flag:
                lx.append(n)
            else:
                ly.append(n)
            n = 0
        flag = not flag

lx.sort()
ly.sort()
sx = sum(lx)
sy = sum(ly)

if sx < x or (sx - x) % 2 == 1 or sy < y or (sy - y) % 2 == 1:
    print('No')
    exit()


def main(x, sx, lx):
    goal = (sx - x) // 2
    if goal == 0:
        return True
    
    # return (sum of some lx == goal)
    dp = [False] * (goal + 1)
    dp[0] = True
    for i in lx:
        if i > goal:
            return False
        for j in range(goal - i, -1, -1):
            if dp[j]:
                dp[j+i] = True
        if dp[goal]:
            return False
    return False


if main(x, sx, lx) and main(y, sy, ly):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

lx, ly = [], []
flag = True
n = 0
s += 'T'
for i in s:
    if i == 'F':
        n += 1
    else:
        if n > 0:
            if flag:
                lx.append(n)
            else:
                ly.append(n)
            n = 0
        flag = not flag

lx.sort()
ly.sort()
sx = sum(lx)
sy = sum(ly)

if sx < x or (sx - x) % 2 == 1 or sy < y or (sy - y) % 2 == 1:
    print('No')
    exit()


def main(x, sx, lx):
    goal = (sx - x) // 2
    if goal == 0:
        return True
    
    # return (sum of some lx == goal)
    dp = [False] * (goal + 1)
    dp[0] = True
    for i in lx:
        if i > goal:
            return False
        for j in range(goal - i, -1, -1):
            if dp[j]:
                dp[j+i] = True
        if dp[goal]:
            return True
    return False


if main(x, sx, lx) and main(y, sy, ly):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

lx, ly = [], []
flag = True
n = 0
for i in s:
    if i == 'F':
        n += 1
    else:
        if n > 0:
            if flag:
                lx.append(n)
            else:
                ly.append(n)
            n = 0
        flag = not flag
if n > 0:
    if flag:
        lx.append(n)
    else:
        ly.append(n)

lx.sort()
ly.sort()
sx = sum(lx)
sy = sum(ly)

if sx < x or (sx - x) % 2 == 1 or sy < y or (sy - y) % 2 == 1:
    print('No')
    exit()


def main(x, sx, lx):
    goal = (sx - x) // 2
    if goal == 0:
        return True
    
    # return (sum of some lx == goal)
    dp = [False] * (goal + 1)
    dp[0] = True
    for i in lx:
        if i > goal:
            return False
        for j in range(goal - i, -1, -1):
            if dp[j]:
                dp[j+i] = True
        if dp[goal]:
            return True
    return False


if main(x, sx, lx) and main(y, sy, ly):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

lx, ly = [], []
flag = True
n = 0
for i in s:
    if i == 'F':
        n += 1
    else:
        if n > 0:
            if flag:
                lx.append(n)
            else:
                ly.append(n)
            n = 0
        flag = not flag
if n > 0:
    if flag:
        lx.append(n)
    else:
        ly.append(n)

lx.sort()
ly.sort()
sx = sum(lx)
sy = sum(ly)

if sx < x or (sx - x) % 2 == 1 or sy < y or (sy - y) % 2 == 1:
    print('No')
    exit()


def main(x, sx, lx):
    goal = (sx - x) // 2
    if goal == 0:
        return True
    
    # return (sum of some lx == goal)
    dp = [False] * (goal + 1)
    dp[0] = True
    for i in lx:
        if i > goal:
            return False
        for j in range(goal - i + 1):
            if dp[j]:
                dp[j+i] = True
        if dp[goal]:
            return True
    return False


if main(x, sx, lx) and main(y, sy, ly):
    print('No')
else:
    print('No')

Submission status: Wrong Answer

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

lx, ly = [], []
flag = True
n = 0
for i in s:
    if i == 'F':
        n += 1
    else:
        if n > 0:
            if flag:
                lx.append(n)
            else:
                ly.append(n)
            n = 0
        flag = not flag
if n > 0:
    if flag:
        lx.append(n)
    else:
        ly.append(n)

lx.sort()
ly.sort()
sx = sum(lx)
sy = sum(ly)

if sx < x or (sx - x) % 2 == 1 or sy < y or (sy - y) % 2 == 1:
    print('Yes')
    exit()


def main(x, sx, lx):
    goal = (sx - x) // 2
    if goal == 0:
        return True
    
    # return (sum of some lx == goal)
    dp = [False] * (goal + 1)
    dp[0] = True
    for i in lx:
        if i > goal:
            return False
        for j in range(goal - i + 1):
            if dp[j]:
                dp[j+i] = True
        if dp[goal]:
            return True
    return False


if main(x, sx, lx) and main(y, sy, ly):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

lx, ly = [], []
flag = True
n = 0
for i in s:
    if i == 'F':
        n += 1
    else:
        if n > 0:
            if flag:
                lx.append(n)
            else:
                ly.append(n)
            n = 0
        flag = not flag
if n > 0:
    if flag:
        lx.append(n)
    else:
        ly.append(n)

lx.sort()
ly.sort()
sx = sum(lx)
sy = sum(ly)

if sx < x or (sx - x) % 2 == 1 or sy < y or (sy - y) % 2 == 1:
    print('No')
    exit()


def main(x, sx, lx):
    goal = (sx - x) // 2
    if goal == 0:
        return True
    
    # sum of some lx == goal ?
    dp = [False] * (goal + 1)
    dp[0] = True
    for i in lx:
        if i > goal:
            return False
        for j in range(goal - i + 1):
            if dp[j]:
                dp[j+i] = True
        if dp[goal]:
            return True
    return False


if main(x, sx, lx) and main(y, sy, ly):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

dpx = [0 for i in range(17000)]
dpy = [0 for i in range(17000)]

dpx[8500] = 1
dpy[8500] = 1

f = s.split("T")

fx = []
fy = []

for i, fi in enumerate(f):
    if i % 2:
        fy.append(len(fi))
    else:
        fx.append(len(fi))

for i, fxi in enumerate(fx):
    for j in range(17000):
        if dpx[j]:
            if fxi + j < 17000:
                dpx[fxi + j] = 1
            if i > 0 and j - fxi >= 0:
                dpx[j - fxi] = 1
        
for fyi in fy:
    for j in range(17000):
        if dpy[j]:
            if fyi + j < 17000:
                dpy[fyi + j] = 1
            if j - fyi >= 0:
                dpy[j - fyi] = 1

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

Submission status: Wrong Answer

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

nx, ny = 0, 0
flag = True
for i in s:
    if i == 'F':
        if flag:
            nx += 1
        else:
            ny += 1
    else:
        flag = not flag

if nx >= abs(x) and (nx - x) % 2 == 0 and ny >= abs(y) and (ny - y) % 2 == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
if 'T' not in s:
  if len(s)==x and y==0:
    print('Yes')
  else:
    print('No')
else:
  move=s.split('T')
  xmove=[len(move[2*i+2]) for i in range((len(move)-1)//2)]
  ymove=[len(move[2*i+1]) for i in range(len(move)//2)]
  import numpy as np
  # 8000を0とする
  ablex=np.zeros(16001,int)
  abley=np.zeros(16001,int)
  ablex[8000+len(move[0])]=1
  abley[8000]=1
  for xi in xmove:
    if xi==0:continue
    ax=np.zeros(16001,int)
    ax[xi:]+=ablex[:-xi]
    ax[:-xi]+=ablex[xi:]
    ablex=ax
  for yi in ymove:
    if yi==0:continue
    ay=np.zeros(16001,int)
    ay[yi:]+=abley[:-yi]
    ay[:-yi]+=abley[yi:]
    abley=ay
  if ablex[8000+x]==1 and abley[8000+y]==1:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
def resolve():
    S = input()
    X, Y = list(map(int, input().split()))
    insts = []
    cnt = 1
    series = S[0]

    for i in range(1, len(S)):
        if series == S[i]:
            cnt += 1
        else:
            insts.append((series, cnt))
            cnt = 1
            series = S[i]
    insts.append((series, cnt))
    # print(insts)
    xmoves = []
    ymoves = []
    to_x = True
    for inst in insts:
        if inst[0] == "F":
            if to_x:
                xmoves.append(inst[1])
            else:
                ymoves.append(inst[1])
        else:
            if inst[1]%2 == 1:
                to_x = not to_x
    # print(xmoves)
    # print(ymoves)
    cands = set()
    cands.add(0)
    for x in xmoves:
        _cands = set()
        while cands:
            xpos = cands.pop()
            _cands.add(xpos+x)
            _cands.add(xpos-x)
        cands = _cands
    if X not in cands:
        print("No")
        return

    cands = set()
    cands.add(0)
    for y in ymoves:
        _cands = set()
        while cands:
            ypos = cands.pop()
            _cands.add(ypos+y)
            _cands.add(ypos-y)
        cands = _cands
    if Y not in cands:
        print("No")
        return
    
    print("Yes")

if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

Solution code:
S = input()
gx, gy = map(int, input().split())
SL = S.split('T')
D = [len(sli) for sli in SL]
DX = D[::2]
DY = D[1::2]

from collections import deque
def reachable(D, g):
    # 命令, 位置
    q = deque([[-1, 0]])

    while q:
        i, x = q.popleft()
        if i == len(D)-1 and x == g:
            return 1
        elif i == len(D)-1:
            continue
        i += 1
        q.append([i, x+D[i]])
        q.append([i, x-D[i]])
    else:
        return 0

if reachable(DX, gx) and reachable(DY, gy):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
def func_dp(z, position):
    len_z = len(z)
    sum_z = sum(z)
    dp = [[0 for _ in range(sum_z * 2 + 1)] for _ in range(len_z + 1)]
    dp[0][sum_z] = 1
    for i in range(len_z):
        for j in range(sum_z * 2 + 1):
            if 0 <= j - z[i] < len(dp[0]):
                t = dp[i][j - z[i]]
            else:
                t = 0
            if 0 <= j + z[i] < len(dp[0]):
                tt = dp[i][j + z[i]]
            else:
                tt = 0
            dp[i + 1][j] = t | tt
    return dp

s = input()
x, y = map(int, input().split())
x_list = []
y_list = []
check = 1
tmp = 0
for i in range(len(s)):
    if s[i] == 'T':
        if tmp > 0:
            if check == 1:
                x_list.append(tmp)
            else:
                y_list.append(tmp)                
        check *= (-1)
        tmp = 0
        continue
    tmp += 1
if tmp > 0:
    if check == 1:
        x_list.append(tmp)
    else:
        y_list.append(tmp)

dp_x = func_dp(x_list, x)
dp_y = func_dp(y_list, y)

if (sum(x_list) < abs(x)) | (sum(y_list) < abs(y)):
    print('No')
    exit()

if (dp_x[-1][x + sum(x_list)] == 1) & (dp_y[-1][y + sum(y_list)] == 1):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
xpossible=[0]
ypossible=[0]
j=0
while s[j]=='F':
  j+=1
  xpossible[0]+=1
  if j==len(s):
    break
counter=0
for i in range(j,len(s)):
  current=0
  while s[i]=='F':
    i+=1
    current+=1
    if i==len(s):
      break
  r=set()
  if counter==0:
    for j in xpossible:
      r.add(j+current)
      r.add(j-current)
    xpossible=[]
    for j in r:
      xpossible.append(j)
  else:
    for j in ypossible:
      r.add(j+current)
      r.add(j-current)
    ypossible=[]
    for j in r:
      ypossible.append(j)
  if i==len(s):
    break
  current=0
  while s[i]=='T':
    i+=1
    current+=1
    if i==len(s):
      break
  counter=(counter+current)%2
if x in xpossible and y in ypossible:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
counter0=0
counter1=0
counter=0
turnonce=0
first=0
for i in range(len(s)):
  if s[i]=='F':
    if counter==0:
      counter0+=1
      if turnonce==0:
        first+=1
    else:
      counter1+=1
  else:
    turnonce=1
    counter=1-counter
if abs(x)>counter0 or abs(y)>counter1:
  print('No')
elif x<first-(counter0-first):
  print('No')
else:
  if abs(x)%2==counter0%2 and abs(y)%2==counter1%2:
    if turnonce==0:
      if x>=0 and x==counter0:
        print('Yes')
      else:
        print('No')
    else:
      print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
counter0=0
counter1=0
counter=0
turnonce=0
for i in range(len(s)):
  if s[i]=='F':
    if counter==0:
      counter0+=1
    else:
      counter1+=1
  else:
    turnonce+=1
    counter=1-counter
if abs(x)>counter0 or abs(y)>counter1:
  print('No')
else:
  if abs(x)%2==counter0%2 and abs(y)%2==counter1%2:
    if turnonce<=1:
      if x>=0 and x==counter0:
        print('Yes')
      else:
        print('No')
    else:
      print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
counter0=0
counter1=0
counter=0
turnonce=0
for i in range(len(s)):
  if s[i]=='F':
    if counter==0:
      counter0+=1
    else:
      counter1+=1
  else:
    turnonce=1
    counter=1-counter
if abs(x)>counter0 or abs(y)>counter1:
  print('No')
else:
  if abs(x)%2==counter0%2 and abs(y)%2==counter1%2:
    if turnonce==0:
      if x>=0 and x==counter0:
        print('Yes')
      else:
        print('No')
    else:
      print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
counter0=0
counter1=0
counter=0
turnonce=0
for i in range(len(s)):
  if s[i]=='F':
    if counter==0:
      counter0+=1
    else:
      counter1+=1
  else:
    turnonce=1
    counter=1-counter
if abs(x)>counter0 or abs(y)>counter1:
  print('No')
else:
  if abs(x)%2==counter0%2 and abs(y)%2==counter1%2:
    if turnonce==0:
      if x>=0:
        print('Yes')
      else:
        print('No')
    else:
      print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
counter0=0
counter1=0
counter=0
for i in range(len(s)):
  if s[i]=='F':
    if counter==0:
      counter0+=1
    else:
      counter1+=1
  else:
    counter=1-counter
if abs(x)>counter0 or abs(y)>counter1:
  print('No')
else:
  if abs(x)%2==counter0%2 and abs(y)%2==counter1%2:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
ss=[len(i) for i in s.split("T")]
print(ss)
x-=ss[0]
a=[]
b=[]
for i in range(1,len(ss)):
  if ss[i]==0:continue
  if i%2==1:b.append(ss[i])
  else:a.append(ss[i])
x=abs(x)
y=abs(y)
exit()
def check(n,a):
  dp=[[0]*20001 for _ in range(len(a)+1)]
  n+=10000
  dp[0][10000]=1
  for i in range(1,len(a)+1):
    for j in range(20001):
      if j+a[i-1]<=20000:dp[i][j+a[i-1]]|=dp[i-1][j]
      if j-a[i-1]>=0:dp[i][j-a[i-1]]|=dp[i-1][j]
  if dp[len(a)][n]==1:return True
  return False
if check(x,a) and check(y,b):print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
s = input()
gx,gy = map(int, input().split())

x_lis=[]
y_lis=[]

cnt=0
now="x"
for i in range(len(s)):
    if s[i]=="F":
        cnt+=1
    else:
        if now=="x":
            x_lis.append(cnt)
            now="y"
        else:
            y_lis.append(cnt)
            now="x"
        cnt=0

if now=="x":
    x_lis.append(cnt)
    now="y"
else:
    y_lis.append(cnt)
    now="x"

now=set([0])
for i in range(len(x_lis)):
    nxt=set()
    for itm in now:
        nxt.add(itm + x_lis[i])
        if i!=0:
            nxt.add(itm - x_lis[i])
    now=nxt

if not gx in now:
    print("No")
    exit()

now=set([0])
for i in range(len(x_lis)):
    nxt=set()
    for itm in now:
        nxt.add(itm + x_lis[i])
        nxt.add(itm - x_lis[i])
    now=nxt

if not gy in now:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

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

x1 = []
y1 = []
cnt = 0
cnt2 = 0

for i in range(len(s)):
    s1 = s[i]
    if s1 == 'F':
        cnt += 1
    else:
        if cnt2 == 0:
            x -= cnt
        elif cnt2 % 2 == 0:
            x1.append(cnt)
        else:
            y1.append(cnt)
        cnt = 0
        cnt2 += 1

if cnt > 0 and cnt2 > 0:
    if cnt2 % 2 == 0:
        x1.append(cnt)
    else:
        y1.append(cnt)

if sum(x1) < abs(x) or sum(y1) < abs(y):
    print('No')
    exit()

dp1 = [[False] * (sum(x1)+1)*2 for _ in range((len(x1)+1))]
dp2 = [[False] * (sum(y1)+1)*2 for _ in range((len(y1)+1))]
dp1[0][sum(x1)+1] = True
dp2[0][sum(y1)+1] = True

for i in range(len(x1)):
    for j in range((sum(x1)+1)*2):
        if dp1[i][j]:
            dp1[i+1][j+x1[i]] = True
            dp1[i+1][j-x1[i]] = True

for i in range(len(y1)):
    for j in range((sum(y1)+1)*2):
        if dp2[i][j]:
            dp2[i+1][j+y1[i]] = True
            dp2[i+1][j-y1[i]] = True

if dp1[-1][sum(x1)+1+x] and dp2[-1][sum(y1)+1+y]:
    print('Yes')
else:
    print('No')