Problem:


Score : 500 points

Problem Statement

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

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

F : Move in the current direction by distance 1.

T : Turn 90 degrees, either clockwise or counterclockwise.

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

Constraints

s consists of F and T.

1 \leq |s| \leq 8 000

x and y are integers.

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

Input

Input is given from Standard Input in the following format:

s
x y

Output

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

Sample Input 1

FTFFTFFF
4 2

Sample Output 1

Yes

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

Sample Input 2

FTFFTFFF
-2 -2

Sample Output 2

Yes

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

Sample Input 3

FF
1 0

Sample Output 3

No

Sample Input 4

TF
1 0

Sample Output 4

No

Sample Input 5

FFTTFF
0 0

Sample Output 5

Yes

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

Sample Input 6

TTTT
1 0

Sample Output 6

No



Sample input:
FTFFTFFF
4 2


Sample output:
Yes

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


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

s = input()
X, Y = getNM()
list_s = s.split('T')
N = len(list_s)

# 最初に進んだ分
X -= len(list_s[0])
x_list = []
y_list = []

for i in range(1, N):
    if i % 2 == 0:
        x_list.append(len(list_s[i]))
    else:
        y_list.append(len(list_s[i]))

def part_sum(list, limit):
    n = len(list)
    dp = [[0] * (2 * limit + 1) for i in range(n + 1)]
    dp[0][limit] = 1

    for i in range(n):
        for j in range(2 * limit + 1):
            if dp[i][j] >= 1:
                dp[i + 1][j - list[i]] += dp[i][j]
                dp[i + 1][j + list[i]] += dp[i][j]

    return dp

if (sum(x_list) == 0 and X != 0) or (sum(y_list) == 0 and Y != 0):
    print('No')
    exit()

if part_sum(x_list, sum(x_list))[-1][X + sum(x_list)] >= 1 and part_sum(y_list, sum(y_list))[-1][Y + sum(y_list)] >= 1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


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

s = input()
X, Y = getNM()
list_s = s.split('T')
N = len(list_s)

# 最初に進んだ分
X -= len(list_s[0])
x_list = []
y_list = []

x_cnt = 0
y_cnt = 0
for i in range(1, N):
    if i % 2 == 0:
        x_cnt += len(list_s[i])
        x_list.append(len(list_s[i]))
    else:
        y_cnt += len(list_s[i])
        y_list.append(len(list_s[i]))

def part_sum(list, limit):
    n = len(list)
    dp = [[0] * (limit + 1) for i in range(n + 1)]
    dp[0][0] = 1

    for i in range(n):
        for j in range(limit + 1):
            if j - list[i] >= 0:
                dp[i + 1][j] += dp[i][j - list[i]]
            if j + list[i] <= limit:
                dp[i + 1][j] += dp[i][j + list[i]]

    return dp

if part_sum(x_list, x_cnt + 1)[-1][X] >= 1 and part_sum(y_list, y_cnt + 1)[-1][Y] >= 1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


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

s = input()
X, Y = getNM()
list_s = s.split('T')
N = len(list_s)

# 最初に進んだ分
X -= len(list_s[0])
x_list = []
y_list = []

for i in range(1, N):
    if i % 2 == 0:
        x_list.append(len(list_s[i]))
    else:
        y_list.append(len(list_s[i]))

def part_sum(list, limit):
    n = len(list)
    dp = [[0] * (limit + 1) for i in range(n + 1)]
    dp[0][0] = 1

    for i in range(n):
        for j in range(limit + 1):
            if j - list[i] >= 0:
                dp[i + 1][j] += dp[i][j - list[i]]
            if j + list[i] <= limit:
                dp[i + 1][j] += dp[i][j + list[i]]

    return dp

if part_sum(x_list, 8001)[-1][abs(X)] >= 1 and part_sum(y_list, 8001)[-1][abs(Y)] >= 1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
from collections import Counter
s = list(input())
x, y = map(int, input().split())
cs = Counter(s)

ss = []
idx = 0
cnt = 0
while idx < len(s):
    if s[idx] == 'F':
        cnt += 1
    else:
        if cnt != 0:
            ss += [cnt]
        ss += [0]
        cnt = 0

    idx += 1

    if idx == len(s):
        if cnt != 0:
            ss += [cnt]

p = [[], []]
now = 0

for i in ss:
    if i == 0:
        now = abs(1-now)
    else:
        p[now] += [i]

s1 = p[0]
s2 = p[1]

if len(s1) == 0 and len(s2) == 0:
    if x == 0 and y == 0:
        print('Yes')
    else:
        print('No')
    exit()

if len(s1) > 0:
    dp = [[0]*(2*max(2*x, sum(s1))+1) for _ in range(len(s1)+1)]
    zero = sum(s1)
    dp[0][zero] = 1
    sum_s1 = sum(s1)
    for i in range(len(s1)):
        m = s1[i]
        for j in range(sum_s1+1):
            if 0 < zero+j+m < 2*sum_s1 and 2*sum_s1 >  zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m] | dp[i][zero+j+m]
            elif 0 < zero+j+m < 2*sum_s1:
                dp[i+1][zero+j] = dp[i][zero+j+m]
            elif 2*sum_s1 > zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m]

            if 0 < zero-j+m < 2*sum_s1 and 2*sum_s1 > zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m] | dp[i][zero-j+m]
            elif 0 < zero-j+m < 2*sum_s1:
                dp[i+1][zero-j] = dp[i][zero-j+m]
            elif 2*sum_s1 > zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m]

    if dp[-1][x+zero] == 0:
        print('No')
        exit()
else:
    if x != 0:
        print('No')
        exit()

if len(s2) > 0:
    dp = [[0]*(2*max(2*y, sum(s2))+1) for _ in range(len(s2)+1)]
    zero = sum(s2)
    dp[0][zero] = 1
    sum_s2 = sum(s2)
    for i in range(len(s2)):
        m = s2[i]
        for j in range(sum_s2+1):
            if 0 < zero+j+m < 2*sum_s2 and 2*sum_s2 > zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m] | dp[i][zero+j+m]
            elif 0 < zero+j+m < 2*sum_s2:
                dp[i+1][zero+j] = dp[i][zero+j+m]
            elif 2*sum_s2 > zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m]

            if 0 < zero-j+m < 2*sum_s2 and 2*sum_s2 > zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m] | dp[i][zero-j+m]
            elif 0< zero-j+m < 2*sum_s2:
                dp[i+1][zero-j] = dp[i][zero-j+m]
            elif 2*sum_s2 > zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m]
    if dp[-1][y+zero] == 0:
        print('No')
        exit()
else:
    if y != 0:
        print('No')
        exit()
print('Yes')

Submission status: Runtime Error

Solution code:
from collections import Counter
s = list(input())
x, y = map(int, input().split())
cs = Counter(s)

ss = []
idx = 0
cnt = 0
while idx < len(s):
    if s[idx] == 'F':
        cnt += 1
    else:
        if cnt != 0:
            ss += [cnt]
        ss += [0]
        cnt = 0

    idx += 1

    if idx == len(s):
        if cnt != 0:
            ss += [cnt]

p = [[], []]
now = 0

for i in ss:
    if i == 0:
        now = abs(1-now)
    else:
        p[now] += [i]

s1 = p[0]
s2 = p[1]
print(s1, s2)

if len(s1) == 0 and len(s2) == 0:
    if x == 0 and y == 0:
        print('Yes')
    else:
        print('No')
    exit()

if len(s1) > 0:
    dp = [[0]*(2*max(2*x, sum(s1))+1) for _ in range(len(s1)+1)]
    zero = sum(s1)
    dp[0][zero] = 1
    sum_s1 = sum(s1)
    for i in range(len(s1)):
        m = s1[i]
        for j in range(sum_s1+1):
            if 0 < zero+j+m < 2*sum_s1 and 2*sum_s1 >  zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m] | dp[i][zero+j+m]
            elif 0 < zero+j+m < 2*sum_s1:
                dp[i+1][zero+j] = dp[i][zero+j+m]
            elif 2*sum_s1 > zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m]

            if 0 < zero-j+m < 2*sum_s1 and 2*sum_s1 > zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m] | dp[i][zero-j+m]
            elif 0 < zero-j+m < 2*sum_s1:
                dp[i+1][zero-j] = dp[i][zero-j+m]
            elif 2*sum_s1 > zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m]

    if dp[-1][x+zero] == 0:
        print('No')
        exit()
else:
    if x != 0:
        print('No')
        exit()

if len(s2) > 0:
    dp = [[0]*(2*max(2*y, sum(s2))+1) for _ in range(len(s2)+1)]
    zero = sum(s2)
    dp[0][zero] = 1
    sum_s2 = sum(s2)
    for i in range(len(s2)):
        m = s2[i]
        for j in range(sum_s2+1):
            if 0 < zero+j+m < 2*sum_s2 and 2*sum_s2 > zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m] | dp[i][zero+j+m]
            elif 0 < zero+j+m < 2*sum_s2:
                dp[i+1][zero+j] = dp[i][zero+j+m]
            elif 2*sum_s2 > zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m]

            if 0 < zero-j+m < 2*sum_s2 and 2*sum_s2 > zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m] | dp[i][zero-j+m]
            elif 0< zero-j+m < 2*sum_s2:
                dp[i+1][zero-j] = dp[i][zero-j+m]
            elif 2*sum_s2 > zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m]
    if dp[-1][y+zero] == 0:
        print('No')
        exit()
else:
    if y != 0:
        print('No')
        exit()
print('Yes')

Submission status: Runtime Error

Solution code:
from collections import Counter
s = list(input())
x, y = map(int, input().split())
cs = Counter(s)

ss = []
idx = 0
cnt = 0
while idx < len(s):
    if s[idx] == 'F':
        cnt += 1
    else:
        if cnt != 0:
            ss += [cnt]
        ss += [0]
        cnt = 0

    idx += 1

    if idx == len(s):
        if cnt != 0:
            ss += [cnt]

p = [[], []]
now = 0

for i in ss:
    if i == 0:
        now = abs(1-now)
    else:
        p[now] += [i]

s1 = p[0]
s2 = p[1]

if len(s1) == 0 and len(s2) == 0:
    if x == 0 and y == 0:
        print('Yes')
    else:
        print('No')
    exit()

if len(s1) > 0:
    dp = [[0]*(2*max(2*x, sum(s1))+1) for _ in range(len(s1)+1)]
    zero = sum(s1)
    dp[0][zero] = 1
    sum_s1 = sum(s1)
    for i in range(len(s1)):
        m = s1[i]
        for j in range(sum_s1+1):
            if zero+j+m < 2*sum_s1 and zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m] | dp[i][zero+j+m]
            elif zero+j+m < 2*sum_s1:
                dp[i+1][zero+j] = dp[i][zero+j+m]
            elif zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m]

            if zero-j+m < 2*sum_s1 and zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m] | dp[i][zero-j+m]
            elif zero-j+m < 2*sum_s1:
                dp[i+1][zero-j] = dp[i][zero-j+m]
            elif zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m]

    if dp[-1][x+zero] == 0:
        print('No')
        exit()
else:
    if x != 0:
        print('No')
        exit()

if len(s2) > 0:
    dp = [[0]*(2*max(2*y, sum(s2))+1) for _ in range(len(s2)+1)]
    zero = sum(s2)
    dp[0][zero] = 1
    sum_s2 = sum(s2)
    for i in range(len(s2)):
        m = s2[i]
        for j in range(sum_s2+1):
            if zero+j+m < 2*sum_s2 and zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m] | dp[i][zero+j+m]
            elif zero+j+m < 2*sum_s2:
                dp[i+1][zero+j] = dp[i][zero+j+m]
            elif zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m]

            if zero-j+m < 2*sum_s2 and zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m] | dp[i][zero-j+m]
            elif zero-j+m < 2*sum_s2:
                dp[i+1][zero-j] = dp[i][zero-j+m]
            elif zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m]
    if dp[-1][y+zero] == 0:
        print('No')
        exit()
else:
    if y != 0:
        print('No')
        exit()
print('Yes')

Submission status: Runtime Error

Solution code:
from collections import Counter
s = list(input())
x, y = map(int, input().split())
cs = Counter(s)

ss = []
idx = 0
cnt = 0
while idx < len(s):
    if s[idx] == 'F':
        cnt += 1
    else:
        if cnt != 0:
            ss += [cnt]
        ss += [0]
        cnt = 0

    idx += 1

    if idx == len(s):
        if cnt != 0:
            ss += [cnt]

p = [[], []]
now = 0

for i in ss:
    if i == 0:
        now = abs(1-now)
    else:
        p[now] += [i]

s1 = p[0]
s2 = p[1]

if len(s1) == 0 and len(s2) == 0:
    print('No')
    exit()

if len(s1) > 0:
    dp = [[0]*(2*max(2*x, sum(s1))+1) for _ in range(len(s1)+1)]
    zero = sum(s1)
    dp[0][zero] = 1
    sum_s1 = sum(s1)
    for i in range(len(s1)):
        m = s1[i]
        for j in range(sum_s1+1):
            if zero+j+m < 2*sum_s1 and zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m] | dp[i][zero+j+m]
            elif zero+j+m < 2*sum_s1:
                dp[i+1][zero+j] = dp[i][zero+j+m]
            elif zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m]

            if zero-j+m < 2*sum_s1 and zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m] | dp[i][zero-j+m]
            elif zero-j+m < 2*sum_s1:
                dp[i+1][zero-j] = dp[i][zero-j+m]
            elif zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m]

    if dp[-1][x+zero] == 0:
        print('No')
        exit()

if len(s2) > 0:
    dp = [[0]*(2*max(2*y, sum(s2))+1) for _ in range(len(s2)+1)]
    zero = sum(s2)
    dp[0][zero] = 1
    sum_s2 = sum(s2)
    for i in range(len(s2)):
        m = s2[i]
        for j in range(sum_s2+1):
            if zero+j+m < 2*sum_s2 and zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m] | dp[i][zero+j+m]
            elif zero+j+m < 2*sum_s2:
                dp[i+1][zero+j] = dp[i][zero+j+m]
            elif zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m]

            if zero-j+m < 2*sum_s2 and zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m] | dp[i][zero-j+m]
            elif zero-j+m < 2*sum_s2:
                dp[i+1][zero-j] = dp[i][zero-j+m]
            elif zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m]
    if dp[-1][y+zero] == 0:
        print('No')
        exit()

print('Yes')

Submission status: Runtime Error

Solution code:
from collections import Counter
s = list(input())
x, y = map(int, input().split())
cs = Counter(s)

ss = []
idx = 0
cnt = 0
while idx < len(s):
    if s[idx] == 'F':
        cnt += 1
    else:
        if cnt != 0:
            ss += [cnt]
        ss += [0]
        cnt = 0

    idx += 1

    if idx == len(s):
        if cnt != 0:
            ss += [cnt]

p = [[], []]
now = 0

for i in ss:
    if i == 0:
        now = abs(1-now)
    else:
        p[now] += [i]

s1 = p[0]
s2 = p[1]

if len(s1) == 0 and len(s2) == 0:
    print('No')
    exit()

if len(s1) > 0:
    dp = [[0]*(2*sum(s1)+1) for _ in range(len(s1)+1)]
    zero = sum(s1)
    dp[0][zero] = 1
    sum_s1 = sum(s1)
    for i in range(len(s1)):
        m = s1[i]
        for j in range(sum_s1+1):
            if zero+j+m < 2*sum_s1 and zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m] | dp[i][zero+j+m]
            elif zero+j+m < 2*sum_s1:
                dp[i+1][zero+j] = dp[i][zero+j+m]
            elif zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m]

            if zero-j+m < 2*sum_s1 and zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m] | dp[i][zero-j+m]
            elif zero-j+m < 2*sum_s1:
                dp[i+1][zero-j] = dp[i][zero-j+m]
            elif zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m]

    if dp[-1][x+zero] == 0:
        print('No')
        exit()

if len(s2) > 0:
    dp = [[0]*(2*sum(s2)+1) for _ in range(len(s2)+1)]
    zero = sum(s2)
    dp[0][zero] = 1
    sum_s2 = sum(s2)
    for i in range(len(s2)):
        m = s2[i]
        for j in range(sum_s2+1):
            if zero+j+m < 2*sum_s2 and zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m] | dp[i][zero+j+m]
            elif zero+j+m < 2*sum_s2:
                dp[i+1][zero+j] = dp[i][zero+j+m]
            elif zero+j-m > 0:
                dp[i+1][zero+j] = dp[i][zero+j-m]

            if zero-j+m < 2*sum_s2 and zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m] | dp[i][zero-j+m]
            elif zero-j+m < 2*sum_s2:
                dp[i+1][zero-j] = dp[i][zero-j+m]
            elif zero-j-m > 0:
                dp[i+1][zero-j] = dp[i][zero-j-m]
    if dp[-1][y+zero] == 0:
        print('No')
        exit()

print('Yes')

Submission status: Runtime Error

Solution code:
MAX_SIZE = 16_000
OFFSET = 8_000

X = [[False for _ in range(MAX_SIZE)] for _ in range(2)]
Y = [[False for _ in range(MAX_SIZE)] for _ in range(2)]

s = input()
x, y = input().split()
N = len(s)
x, y = int(x), int(y)

i = 0
d = 0
j = 0
while i < N and s[i] == 'F':
    d += 1
    i += 1
X[j][d + OFFSET] = True

i += 1
d = 0
while i < N and s[i] == 'F':
    d += 1
    i += 1
i += 1
Y[j][d + OFFSET] = True
Y[j][-d + OFFSET] = True

j += 1
while i < N:
    d = 0
    while i < N and s[i] == 'F':
        d += 1
        i += 1
    for k in range(-N + OFFSET, N + OFFSET + 1):
        if k - d >= 0 and k + d < MAX_SIZE:
            X[j % 2][k] = X[(j - 1) % 2][k - d] or X[(j - 1) % 2][k + d]
        elif k - d >= 0:
            X[j % 2][k] = X[(j - 1) % 2][k - d]
        elif k + d < MAX_SIZE:
            X[j % 2][k] = X[(j - 1) % 2][k + d]
    i += 1
    d = 0
    while i < N and s[i] == 'F':
        d += 1
        i += 1
    for k in range(-N + OFFSET, N + OFFSET + 1):
        if k - d >= 0 and k + d < MAX_SIZE:
            Y[j % 2][k] = Y[(j - 1) % 2][k - d] or Y[(j - 1) % 2][k + d]
        elif k - d >= 0:
            Y[j % 2][k] = Y[(j - 1) % 2][k - d]
        elif k + d < MAX_SIZE:
            Y[j % 2][k] = Y[(j - 1) % 2][k + d]
    i += 1
    j += 1

if (X[(j - 1) % 2][x + OFFSET] and Y[(j - 1) % 2][y + OFFSET]):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

stepx = []
stepy = []

headx = True
step = 0
for c in s:
    if c == "F":
        step += 1
    else:
        if headx:
            stepx.append(step)
        else:
            stepy.append(step)
        headx = not headx
        step = 0

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


class Reachable:
    def __init__(self, steps):
        self.steps = steps

        self.maxs = sum(steps)
        self.r = {
            i: {s: None for s in range(-self.maxs, self.maxs + 1)}
            for i in range(len(steps))
        }

    def __call__(self, i, s):
        if i == -1:
            return s == 0
        elif not -self.maxs <= s <= self.maxs:
            return False
        elif self.r[i][s] is not None:
            return self.r[i][s]
        else:
            step = self.steps[i]
            r = self(i - 1, s - step) or self(i - 1, s + step)
            self.r[i][s] = r
            return r


rx = Reachable(stepx)
ry = Reachable(stepy)
answer = rx(len(stepx) - 1, x) and ry(len(stepy) - 1, y)
if answer:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from itertools import groupby
import sys
def main(s, x, y):
    g = [x, y]
    o = [[], []]

    direction = count = 0
    first = True
    for c in s:
        if c == 'T':
            if first:
                g[0] -= count
                first = False
            elif count > 0:
                o[direction].append(count)
            count = 0
            direction ^= 1
        else:
            count += 1
    if first:
        g[0] -= count
    elif count > 0:
        o[direction].append(count)

    for d in range(2):
        l = o[d]
        M = sum(l)
        M2 = M * 2
        if abs(g[d]) > M:
            print('No')
            return
        pre = [False] * (M2 + 1)
        pre[M] = True
        for i, v in enumerate(l):
            dp = [False] * (M2 + 1)
            for a in range(M2 + 1):
                if pre[a] == False: continue
                if a >= v:
                    dp[a - v] = True
                if a + v <= M2:
                    dp[a + v] = True
            pre = dp
        if dp[g[d] + M] == False:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    input = sys.stdin.readline
    s = input().rstrip()
    x, y = map(int, input().split())
    main(s, x, y)

Submission status: Runtime Error

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 x != []:
    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: Runtime Error

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

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: Runtime Error

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

xs = []
ys = []
isx = True
i = 0
n = len(s)
while i<n and s[i]=="F":
    x -= 1
    i += 1

while i<n:
    c = 0
    while i<n and s[i]=="F":
        i += 1
        c += 1
    if isx and c>0:
        xs.append(c)
    elif c>0:
        ys.append(c)
    isx = not isx
    i += 1
    
def sub(l, target):
    # lの一部の符号を反転してtargetを作れるか
    val = sum(l)
    prev = [False] * (2*(val+1))
    prev[val] = True
    current = None
    for num in l:
        current = [False] * (2*(val+1))
        for i in range(2*(val+1)):
            if i-num>=0 and prev[i-num]:
                current[i] = True
            if i+num<(2*val+2) and prev[i+num]:
                current[i] = True
        prev = current
    if current is None:
        current = prev
    return current[target+val]

if sum(abs(item) for item in xs)>=x and sum(abs(item) for item in ys)>=y and sub(xs, x) and sub(ys, y):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

xs = []
ys = []
isx = True
i = 0
n = len(s)
while i<n and s[i]=="F":
    x -= 1
    i += 1

while i<n:
    c = 0
    while i<n and s[i]=="F":
        i += 1
        c += 1
    if isx and c>0:
        xs.append(c)
    elif c>0:
        ys.append(c)
    isx = not isx
    i += 1
    
def sub(l, target):
    # lの一部の符号を反転してtargetを作れるか
    val = sum(l)
    prev = [False] * (2*(val+1))
    prev[val] = True
    current = None
    for num in l:
        current = [False] * (2*(val+1))
        for i in range(2*(val+1)):
            if i-num>=0 and prev[i-num]:
                current[i] = True
            if i+num<2*val+2 and prev[i+num]:
                current[i] = True
        prev = current
    if current is None:
        current = prev
    return current[target+val]

if sub(xs, x) and sub(ys, y):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = input()
s += "T"
x,y = map(int,input().split())
mvx = []
mvy = []
now = "x"
cnt = 0
for c in s:
    if c == "F": cnt += 1
    else:
        if now == "x":
            mvx.append(cnt)
            now = "y"
        else:
            mvy.append(cnt)
            now = "x"
        cnt = 0

lx = len(mvx)
sx = sum(mvx)
dpx = [[False]*(2*sx+1) for _ in range(lx+1)]
dpx[0][sx] = True
dpx[1][sx+mvx[0]] = True
for i in range(1,lx):
    for j in range(2*sx+1):
        if j-mvx[i] >= 0: dpx[i+1][j] = dpx[i+1][j] | dpx[i][j-mvx[i]]
        if j+mvx[i] <= 2*sx: dpx[i+1][j] = dpx[i+1][j] | dpx[i][j+mvx[i]]

ly = len(mvy)
sy = sum(mvy)
dpy = [[False]*(2*sy+1) for _ in range(ly+1)]
dpy[0][sy] = True
for i in range(ly):
    for j in range(2*sy+1):
        if j-mvy[i] >= 0: dpy[i+1][j] = dpy[i+1][j] | dpy[i][j-mvy[i]]
        if j+mvy[i] <= 2*sy: dpy[i+1][j] = dpy[i+1][j] | dpy[i][j+mvy[i]]

print("Yes" if dpx[-1][x+sx] and dpy[-1][y+sy] else "No")

Submission status: Runtime Error

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

def reachable(D, s, g):
    OFS = 5
    dp = [0] * (2*OFS+1)
    dp[OFS+s] = 1
    for i in range(len(D)):
        d = D[i]
        ndp = [0] * (2*OFS+1)
        for j in range(2*OFS+1):
            try:
                ndp[j] += dp[j-d]
            except:
                pass
            try:
                ndp[j] += dp[j+d]
            except:
                pass
        dp = ndp
    return dp[OFS+g] > 0

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

Submission status: Runtime Error

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)
  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: Runtime Error

Solution code:
s=input()
x,y=map(int,input().split())
xpossible=[0]
ypossible=[0]
j=0
while s[j]=='F':
  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)
  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')