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:
#082-D 個々のFがx方向y方向どちらに進むかは確定しているので、それぞれまとめて、+か-かでbit全探索
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
S=S()
x,y=IL()
Dx=[]
Dy=[]
v="x"
ct=0
cf=0
for s in S:
    if s=="T":
        ct+=1
        if cf!=0:
            if v=="x":
                Dx.append(cf)
            else:
                Dy.append(cf)
            cf=0
    else:
        cf+=1
        if ct!=0:
            if ct%2==1:
                if v=="x":
                    v="y"
                else:
                    v="x"
            ct=0
if cf!=0:
    if v=="x":
         Dx.append(cf)
    else:
         Dy.append(cf)
    cf=0

cnt=0
for s in S:
    if s=="T":
        cnt+=1
    else:
        break

if len(Dx)!=0:
    if cnt!=0 and cnt%2==0:
        flag=True
    else:
        st=Dx[0]
        Dx=Dx[1:]
        flag=False
    
xx=True if (len(Dx)==0 and x==0) else False
if len(Dx)!=0:
    for i in range(2**len(Dx)):
        if flag:
            go=0
        else:
            go=st
        for j in range(len(Dx)):
            if bin(i)[2+j]=="0":
                go+=Dx[j]
            else:
                go-=Dx[j]
        if go==x:
            xx=True
            break
go=0
yy=True if y==0 else False
for i in range(2**len(Dy)):
    go=0
    for j in range(len(Dy)):
        if bin(i)[2+j]=="0":
            go+=Dy[j]
        else:
            go-=Dy[j]
    if go==y:
        yy=True
        break
if xx and yy:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
#082-D 個々のFがx方向y方向どちらに進むかは確定しているので、それぞれまとめて、+か-かでbit全探索
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
S=S()
x,y=IL()
Dx=[]
Dy=[]
v="x"
ct=0
cf=0
for s in S:
    if s=="T":
        ct+=1
        if cf!=0:
            if v=="x":
                Dx.append(cf)
            else:
                Dy.append(cf)
            cf=0
    else:
        cf+=1
        if ct!=0:
            if ct%2==1:
                if v=="x":
                    v="y"
                else:
                    v="x"
            ct=0
if cf!=0:
    if v=="x":
         Dx.append(cf)
    else:
         Dy.append(cf)
    cf=0

cnt=0
for s in S:
    if s=="T":
        cnt+=1
    else:
        break

if len(Dx)!=0:
    if cnt!=0 and cnt%2==0:
        flag=True
    else:
        st=Dx[0]
        Dx=Dx[1:]
        flag=False
    
xx=True if (len(Dx)==0 and x==0) else False
for i in range(2**len(Dx)):
    if flag:
        go=0
    else:
        go=st
    for j in range(len(Dx)):
        if bin(i)[2+j]=="0":
            go+=Dx[j]
        else:
            go-=Dx[j]
    if go==x:
        xx=True
        break
go=0
yy=True if y==0 else False
for i in range(2**len(Dy)):
    go=0
    for j in range(len(Dy)):
        if bin(i)[2+j]=="0":
            go+=Dy[j]
        else:
            go-=Dy[j]
    if go==y:
        yy=True
        break
if xx and yy:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = input()
gx, gy = map(int, input().split())
n = len(s)
X, Y = [], []
x, y, flag = 0, 0, 0
for i in range(n):
    if s[i] == 'F' and flag == 0:
        x += 1
    elif s[i] == 'F' and flag == 1:
        y += 1
    else:
        if flag and y > 0:
            Y.append(y)
            y = 0
        elif not flag and x > 0:
            X.append(x)
            x = 0
        flag = (flag + 1) % 2
if flag and y > 0:
    Y.append(y)
elif not flag and x > 0:
    X.append(x)
gx -= X[0]
if len(X):
    X.pop(0)
for x in sorted(X, reverse = True):
    if gx > 0:
        gx -= x
    else:
        gx += x
for y in sorted(Y, reverse = True):
    if gy > 0:
        gy -= y
    else:
        gy += y
if gx == gy == 0:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = input()
gx, gy = map(int, input().split())
n = len(s)
X, Y = [], []
x, y, flag = 0, 0, 0
for i in range(n):
    if s[i] == 'F' and flag == 0:
        x += 1
    elif s[i] == 'F' and flag == 1:
        y += 1
    else:
        if flag and y > 0:
            Y.append(y)
            y = 0
        elif not flag and x > 0:
            X.append(x)
            x = 0
        flag = (flag + 1) % 2
if flag and y > 0:
    Y.append(y)
elif not flag and x > 0:
    X.append(x)
gx -= X[0]
X.pop(0)
for x in sorted(X, reverse = True):
    if gx > 0:
        gx -= x
    else:
        gx += x
for y in sorted(Y, reverse = True):
    if gy > 0:
        gy -= y
    else:
        gy += y
if gx == gy == 0:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = input()
gx, gy = map(int, input().split())
n = len(s)
X, Y = [], []
x, y, flag = 0, 0, 0
for i in range(n):
    if s[i] == 'F' and flag == 0:
        x += 1
    elif s[i] == 'F' and flag == 1:
        y += 1
    else:
        if flag and y > 0:
            Y.append(y)
            y = 0
        elif not flag and x > 0:
            X.append(x)
            x = 0
        flag = (flag + 1) % 2
if flag and y > 0:
    Y.append(y)
elif not flag and x > 0:
    X.append(x)
MAX_X, MAX_Y, l_X, l_Y = sum(X), sum(Y), len(X), len(Y)
if MAX_X < abs(gx) or MAX_Y < abs(gy):
    print("No")
else:
    dp_x = [[False for _ in range(MAX_X * 2 + 1)] for _ in range(l_X + 1)]
    dp_y = [[False for _ in range(MAX_Y * 2 + 1)] for _ in range(l_Y + 1)]
    dp_x[0][MAX_X], dp_y[0][MAX_Y] = True, True
    for i in range(l_X):
        for x in range(MAX_X * 2 + 1):
            if x + X[i] < MAX_X * 2 + 1:
                dp_x[i + 1][x] |= dp_x[i][x + X[i]]
            if x - X[i] >= 0:
                dp_x[i + 1][x] |= dp_x[i][x - X[i]]
    for i in range(l_Y):
        for y in range(MAX_Y * 2 + 1):
            if y + Y[i] < MAX_Y * 2 + 1:
                dp_y[i + 1][y] |= dp_y[i][y + Y[i]]
            if x - X[i] >= 0:
                dp_y[i + 1][y] |= dp_y[i][y - Y[i]]
    if dp_x[l_X][gx + MAX_X] and dp_y[l_Y][gy + MAX_Y]:
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
s = input()
gx, gy = map(int, input().split())
n = len(s)
X, Y = [], []
x, y, flag = 0, 0, 0
for i in range(n):
    if s[i] == 'F' and flag == 0:
        x += 1
    elif s[i] == 'F' and flag == 1:
        y += 1
    else:
        if flag and y > 0:
            Y.append(y)
            y = 0
        elif not flag and x > 0:
            X.append(x)
            x = 0
        flag = (flag + 1) % 2
if flag and y > 0:
    Y.append(y)
elif not flag and x > 0:
    X.append(x)
MAX_X, MAX_Y, l_X, l_Y = sum(X), sum(Y), len(X), len(Y)
if MAX_X < gx or MAX_Y < gy:
    print("No")
else:
    dp_x = [[False for _ in range(MAX_X * 2 + 1)] for _ in range(l_X + 1)]
    dp_y = [[False for _ in range(MAX_Y * 2 + 1)] for _ in range(l_Y + 1)]
    dp_x[0][MAX_X], dp_y[0][MAX_Y] = True, True
    for i in range(l_X):
        for x in range(MAX_X * 2 + 1):
            if x + X[i] < MAX_X * 2 + 1:
                dp_x[i + 1][x] |= dp_x[i][x + X[i]]
            if x - X[i] >= 0:
                dp_x[i + 1][x] |= dp_x[i][x - X[i]]
    for i in range(l_Y):
        for y in range(MAX_Y * 2 + 1):
            if y + Y[i] < MAX_Y * 2 + 1:
                dp_y[i + 1][y] |= dp_y[i][y + Y[i]]
            if x - X[i] >= 0:
                dp_y[i + 1][y] |= dp_y[i][y - Y[i]]
    if dp_x[l_X][gx + MAX_X] and dp_y[l_Y][gy + MAX_Y]:
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
import sys

def f(pos, S, goal):
    F = 0
    while len(S) > 0 and S[0] == 'F':
        F += 1
        _ = S.pop(0)

    num_F = sum([c == 'F' for c in S])

    next_pos = set()
    for p in pos:
        x = p[0]
        y = p[1]
        if p[2] == 0:  # Forward to +x
            x += F
        elif p[2] == 1:  # Forward to +y
            y += F
        elif p[2] == 2:  # Forward to -x
            x -= F
        else:              # direct == 3, Foward to -y
            y -= F

        dist = abs(goal[0] - x) + abs(goal[1] - y)
        if num_F < dist:
            continue

        direct1 = (p[2] + 1) % 4
        direct2 = (p[2] + 3) % 4

        np1 = (x, y, direct1)
        np2 = (x, y, direct2)

        next_pos.add(np1)
        next_pos.add(np2)

    if len(next_pos) == 0:
        return False

    if len(S) == 0:
        ans = False
        for p in next_pos:
            if p[0] == goal[0] and p[1] == goal[1]:
                ans = True
                break
        return ans

    _ = S.pop(0)  # Remove 'T' at S[0]
    return f(next_pos, S, goal)


def main():
    input = sys.stdin.readline
    S = [str(c) for c in input().strip()]
    goal = list(map(int, input().split()))

    init = (0, 0, 0)
    pos = set()
    pos.add(init)

    if f(pos, S, goal):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

XY = [[], []]
b = 0
renzoku = 0
for i in range(len(s)) :
    if s[i] == "T" :
        b = (b+1) % 2
        renzoku = 0
    else :
        if renzoku == 0 :
            XY[b].append(1)
            renzoku = 1
        else :
            XY[b][-1] += 1


#print(XY)

g = 8010

X = [[0 for i in range(g*2)] for j in range(len(XY[0]))]
Y = [[0 for i in range(g*2)] for j in range(len(XY[1]))]



if len(XY[0]) > 0 :
    X[0][g+XY[0][0]] = 1
    if s[0] == "T" :
        X[0][g-XY[0][0]] = 1
        
    for i in range(1, len(XY[0])) :
        for j in range(g*2) :
            #print(X)
            if j - XY[0][i] >= 0 and X[i-1][j - XY[0][i]] == 1 :
                X[i][j] = 1
            if j + XY[0][i] <= g*2-1 and X[i-1][j + XY[0][i]] == 1 :
                X[i][j] = 1

if len(XY[1]) > 0 :

    Y[0][g+XY[1][0]] = 1
    Y[0][g-XY[1][0]] = 1
        
    for i in range(1, len(XY[1])) :
        for j in range(20000) :
            if j - XY[1][i] >= 0 and Y[i-1][j - XY[1][i]] == 1 :
                Y[i][j] = 1
            if j + XY[1][i] <= g*2-1 and Y[i-1][j + XY[1][i]] == 1 :
                Y[i][j] = 1

if X == [] :
    X = [[0 for i in range(g*2)]]
if Y == [] :
    Y = [[0 for i in range(g*2)]]

if ((len(XY[0]) == 0 and x == 0) or X[-1][g+x] == 1) and ((len(XY[1]) == 0 and y == 0) or Y[-1][g+y] == 1) :
    print("Yes")
else :
    print("No")

Submission status: Runtime Error

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

XY = [[], []]
b = 0
renzoku = 0
for i in range(len(s)) :
    if s[i] == "T" :
        b = (b+1) % 2
        renzoku = 0
    else :
        if renzoku == 0 :
            XY[b].append(1)
            renzoku = 1
        else :
            XY[b][-1] += 1


#print(XY)

g = 8002

X = [[0 for i in range(g*2)] for j in range(len(XY[0]))]
Y = [[0 for i in range(g*2)] for j in range(len(XY[1]))]



if len(XY[0]) > 0 :
    X[0][g+XY[0][0]] = 1
    if s[0] == "T" :
        X[0][g-XY[0][0]] = 1
        
    for i in range(1, len(XY[0])) :
        for j in range(g*2) :
            #print(X)
            if j - XY[0][i] >= 0 and X[i-1][j - XY[0][i]] == 1 :
                X[i][j] = 1
            if j + XY[0][i] <= g*2-1 and X[i-1][j + XY[0][i]] == 1 :
                X[i][j] = 1

if len(XY[1]) > 0 :

    Y[0][g+XY[1][0]] = 1
    Y[0][g-XY[1][0]] = 1
        
    for i in range(1, len(XY[1])) :
        for j in range(20000) :
            if j - XY[1][i] >= 0 and Y[i-1][j - XY[1][i]] == 1 :
                Y[i][j] = 1
            if j + XY[1][i] <= g*2-1 and Y[i-1][j + XY[1][i]] == 1 :
                Y[i][j] = 1

if X == [] :
    X = [[0 for i in range(g*2)]]
if Y == [] :
    Y = [[0 for i in range(g*2)]]

if ((len(XY[0]) == 0 and x == 0) or X[-1][g+x] == 1) and ((len(XY[1]) == 0 and y == 0) or Y[-1][g+y] == 1) :
    print("Yes")
else :
    print("No")

Submission status: Runtime Error

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

XY = [[], []]
b = 0
renzoku = 0
for i in range(len(s)) :
    if s[i] == "T" :
        b = (b+1) % 2
        renzoku = 0
    else :
        if renzoku == 0 :
            XY[b].append(1)
            renzoku = 1
        else :
            XY[b][-1] += 1


#print(XY)

g = 10

X = [[0 for i in range(g*2)] for j in range(len(XY[0]))]
Y = [[0 for i in range(g*2)] for j in range(len(XY[1]))]



if len(XY[0]) > 0 :
    X[0][g+XY[0][0]] = 1
    if s[0] == "T" :
        X[0][g-XY[0][0]] = 1
        
    for i in range(1, len(XY[0])) :
        for j in range(g*2) :
            #print(X)
            if j - XY[0][i] >= 0 and X[i-1][j - XY[0][i]] == 1 :
                X[i][j] = 1
            if j + XY[0][i] <= g*2-1 and X[i-1][j + XY[0][i]] == 1 :
                X[i][j] = 1

if len(XY[1]) > 0 :

    Y[0][g+XY[1][0]] = 1
    Y[0][g-XY[1][0]] = 1
        
    for i in range(1, len(XY[1])) :
        for j in range(20000) :
            if j - XY[1][i] >= 0 and Y[i-1][j - XY[1][i]] == 1 :
                Y[i][j] = 1
            if j + XY[1][i] <= g*2-1 and Y[i-1][j + XY[1][i]] == 1 :
                Y[i][j] = 1

if X == [] :
    X = [[0 for i in range(g*2)]]
if Y == [] :
    Y = [[0 for i in range(g*2)]]

if ((len(XY[0]) == 0 and x == 0) or X[-1][g+x] == 1) and ((len(XY[1]) == 0 and y == 0) or Y[-1][g+y] == 1) :
    print("Yes")
else :
    print("No")

Submission status: Runtime Error

Solution code:
s = str(input())
l = len(s)
x,y = map(int,input().split())
Fs = []
count = 0
for i in range(l):
    if s[i] == "T":
        Fs.append(count)
        count = 0
    else:
        count+=1
if s[-1] == "F":
    Fs.append(count)
xFs = [Fs[j] for j in range(len(Fs)) if j%2 == 0 and j!=0]
yFs = [Fs[k] for k in range(len(Fs)) if k%2 == 1]
x-=Fs[0]

def part_sum(a,A):
    n = len(a)
    dp = [[0 for i in range(A+1)] for j in range(n+1)]
    dp[0][0]=1
    
    for i in range(n):
        for j in range(A+1):
            if a[i]<=j:
                dp[i+1][j]=dp[i][j-a[i]] or dp[i][j]
            else:
                dp[i+1][j]=dp[i][j]
    return dp[n][A]


if sum(xFs) < abs(x) or sum(yFs) < abs(y):
    print("No")
else:
    if sax%2 == 0 and say%2 == 0:
        sax = int((sum(xFs)-x)/2)
        say = int((sum(yFs)-y)/2)
        if part_sum(xFs,sax) == 1 and part_sum(yFs,say) == 1:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Submission status: Runtime Error

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

command_length = len(command)
x_command = command_length // 2
y_command = command_length // 2
if command_length % 2 != 0:
    x_command += 1

dpx = [[False for _ in range(8000 + 1)] for _ in range(x_command + 1)]
dpx[0][4000] = True
dpy = [[False for _ in range(8000 + 1)] for _ in range(y_command + 1)]
dpy[0][4000] = True

for i in range(1, x_command + 1):
    f = len(command[2 * (i - 1)])
    for j in range(f, 8000 + 1 - f):
        if dpx[i - 1][j - f] or dpx[i - 1][j + f]:
            dpx[i][j] = True

for i in range(1, y_command + 1):
    f = len(command[2 * (i - 1) + 1])
    for j in range(f, 8000 + 1 - f):
        if dpy[i - 1][j - f] or dpy[i - 1][j + f]:
            dpy[i][j] = True

if dpx[x_command][4000 + x] and dpy[y_command][4000 + y]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
s = input()
x, y = map(int, input().split())
movex = []
movey = []

direc = 0
first = None
for elem in s.split('T'):
    if direc == 0:
        if first is not None:
            movex.append(len(elem))
        else:
            fiest = len(elem)
            direc = 1
    else:
        movey.append(len(elem))
        direc = 0
x -= first

n = len(s)
dpx = [[False]*(2*n+1) for _ in range(len(movex)+1)]
dpy = [[False]*(2*n+1) for _ in range(len(movey)+1)]
# dpx = -len(s), -len(s)+1, ..., -1, 0, 1, ..., len(s)-1, len(s)

dpx[0][n] = True
dpy[0][n] = True

for i in range(len(movex)):
    for j in range(2*n+1):
        if j-movex[i] >= 0 and j+movex[i] <= 2*n:
            dpx[i+1][j] = dpx[i][j-movex[i]] or dpx[i][j+movex[i]]
        if j-movex[i] < 0:
            dpx[i+1][j] = dpx[i][j+movex[i]]
        if j+movex[i] > 2*n:
            dpx[i+1][j] = dpx[i][j-movex[i]]
for i in range(len(movey)):
    for j in range(2*n+1):
        if j-movey[i] >= 0 and j+movey[i] <= 2*n:
            dpy[i+1][j] = dpy[i][j-movey[i]] or dpy[i][j+movey[i]]
        if j-movey[i] < 0:
            dpy[i+1][j] = dpy[i][j+movey[i]]
        if j+movey[i] > 2*n:
            dpy[i+1][j] = dpy[i][j-movey[i]]

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

dp0 = [False for i in range(16000)]
dp1 = [False for i in range(16000)]


def reachable(start, target, lst, S):

    global dp0, dp1

    for i in range(S):
        dp1[i] = False
    dp1[target] = True

    for moves in lst[::-1]:
        for i in range(S):
            dp0[i] = False
        for i in range(S):
            if dp1[i]:
                dp0[i + moves] = True
                dp0[i - moves] = True
        dp0, dp1 = dp1, dp0

    return dp1[start]

def main():
    s = input()
    sa = input().split(' ')
    x = int(sa[0])
    y = int(sa[1])

    x_list = []
    y_list = []
    moves = 0
    move_x = True
    lst = x_list
    for cmd in s:
        if cmd == 'F':
            moves += 1
        else:
            if moves != 0:
                lst.append(moves)
            moves = 0
            move_x = not move_x
            lst = x_list if move_x else y_list
    if moves != 0:
        lst.append(moves)

    if 0 < len(x_list):
        x -= x_list[0]
        x_list = x_list[1:]

    len_s = len(s)
    if reachable(len_s, len_s + x, x_list, len_s * 2) and reachable(len_s, len_s + y, y_list, len_s * 2):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

def reachable(start, target, lst, S):

    dp0 = [False for i in range(S)]
    dp1 = [False for i in range(S)]

    dp1[target] = True

    for moves in lst[::-1]:
        for i in range(S):
            dp0[i] = False
        for i in range(S):
            if dp1[i]:
                dp0[i + moves] = True
                dp0[i - moves] = True
        dp0, dp1 = dp1, dp0

    return dp1[start]

def main():
    s = input()
    sa = input().split(' ')
    x = int(sa[0])
    y = int(sa[1])

    x_list = []
    y_list = []
    moves = 0
    move_x = True
    lst = x_list
    for cmd in s:
        if cmd == 'F':
            moves += 1
        else:
            if moves != 0:
                lst.append(moves)
            moves = 0
            move_x = not move_x
            lst = x_list if move_x else y_list
    if moves != 0:
        lst.append(moves)

    if 0 < len(x_list):
        x -= x_list[0]
        x_list = x_list[1:]

    len_s = len(s)
    if reachable(len_s, len_s + x, x_list, len_s * 2) and reachable(len_s, len_s + y, y_list, len_s * 2):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

xcnt = 0
ycnt = 0
tcnt = 0
xsym = 0
ysym = 0
xstep = 0
ystep = 0
start = 0
xli = [0]
yli = [0]
xc = 0
yc = 0
for i in range(len(s)):
    if s[i] == "F":
        if tcnt == 0:
            start += 1
        if tcnt % 2 == 0:
            xcnt += 1
            xc += 1
            if xsym == 0:
                xstep += 1
                xsym = 1
        else:
            ycnt += 1
            yc += 1
            if ysym == 0:
                ystep += 1
                ysym = 1
    else:
        if tcnt % 2 == 0:
            if xc != 0:
                xli.append(xc)
                xc = 0
        else:
            if yc != 0:
                yli.append(yc)
                yc = 0
        tcnt += 1
        xsym = 0
        ysym = 0
if tcnt % 2 == 0:
    xli.append(xc)
    xc = 0
else:
    yli.append(yc)
    yc = 0
#xDPtable
xdp = []
for i in range(xstep + 1):
    xdp.append([])
for i in range(xstep + 1):
    for j in range(2 * xcnt + 1):
        xdp[i].append(False)
#yDPtable
ydp = []
for i in range(ystep + 1):
    ydp.append([])
for i in range(ystep + 1):
    for j in range(2 * ycnt + 1):
        ydp[i].append(False)
#xDp
xdp[0][xcnt] = True
if len(xli) > 1:
    xdp[1][xcnt + start] = True
    for i in range(2, xstep + 1):
        for j in range(2 * xcnt + 1):
            if 0 <= j + xli[i] <= 2 * xcnt and 0 <= j - xli[i] <= 2 * xcnt:
                xdp[i][j] = xdp[i - 1][j + xli[i]] or xdp[i - 1][j - xli[i]]
            elif 0 <= j + xli[i] <= 2 * xcnt:
                xdp[i][j] = xdp[i - 1][j + xli[i]]
            elif 0 <= j - xli[i] <= 2 * xcnt:
                xdp[i][j] = xdp[i - 1][j - xli[i]]
#yDp
ydp[0][ycnt] = True
if len(yli) > 1:
    ydp[1][ycnt + yli[1]] = True
    ydp[1][ycnt - yli[1]] = True
    for i in range(2, ystep + 1):
        for j in range(2 * ycnt + 1):
            if 0 <= j + yli[i] <= 2 * ycnt and 0 <= j - yli[i] <= 2 * ycnt:
                ydp[i][j] = ydp[i - 1][j + yli[i]] or ydp[i - 1][j - yli[i]]
            elif 0 <= j + yli[i] <= 2 * ycnt:
                ydp[i][j] = ydp[i - 1][j + yli[i]]
            elif 0 <= j - yli[i] <= 2 * ycnt:
                ydp[i][j] = ydp[i - 1][j - yli[i]]

if 0 <= xcnt + x <= len(xdp[0]) - 1 and 0 <= ycnt + y <= len(ydp[0]) - 1:
    if xdp[xstep][xcnt + x] == True and ydp[ystep][ycnt + y] == True:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split(" "))
l = [len(c) for c in s.split("T")]
X = l[::2]
Y = l[1::2]

ansX = set([X[0]])
for i in range(1,len(X)):
    ansX = set([c+X[i] for c in ansX]+[c-X[i] for c in ansX]))

ansY = set([0])
for i in range(0,len(Y)):
    ansY = set([c+Y[i] for c in ansY]+[c-Y[i] for c in ansY]))
    
if x in ansX and y in ansY:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = input()+'T'
x,y=map(int,input().split())
di = 0
count = 0
xlis = []
ylis = []
for charas in s:
  if charas == 'F':
    count += 1
  else:
    if count>0:
      if di%2==0:
        xlis.append(count)
      else:
        ylis.append(count)
      count = 0
    di += 1
if xlis==[]:
  xlis.append(0)
x = x-xlis[0]
del xlis[0]
if xlis==[]:
  xlis.append(0)
if ylis==[]:
  ylis.append(0)
def judge(i,x,lis):
  if i == 0:
    if x == 0:
      return True
    else:
      return False
  else:
    return judge(i-1,x+lis[i-1],lis) or judge(i-1,x-lis[i-1],lis)
ans = (judge(len(xlis),x,xlis) and judge(len(ylis),y,ylis))
if ans:
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
s = input()+'T'
x,y=map(int,input().split())
di = 0
count = 0
xlis = []
ylis = []
for charas in s:
  if charas == 'F':
    count += 1
  else:
    if count>0:
      if di%2==0:
        xlis.append(count)
      else:
        ylis.append(count)
      count = 0
    di += 1
if xlis==[]:
  xlis.append(0)
if ylis==[]:
  ylis.append(0)
def judge(i,x,lis):
  if i == 0:
    if x == 0:
      return True
    else:
      return False
  else:
    return judge(i-1,x+lis[i-1],lis) or judge(i-1,x-lis[i-1],lis)
ans = (judge(len(xlis),x,xlis) and judge(len(ylis),y,ylis))
if ans:
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
def main():
    s = input()
    x, y = map(int, input().split())
    if solve(s, x, y):
        print('Yes')
    else:
        print('No')

def solve(s, x, y):
    moves = split_moves(s)
    if not match(x - moves[0][0], moves[0][1:]):
        return False
    if not match(y, moves[1]):
        return False

    return True

def match(x, moves):
    s = sum(moves)
    if x > s:
        return False

    if (s - x) % 2 != 0:
        return False

    return knapsack((s - x) // 2, moves)

def knapsack(x, moves):
    if x == 0:
        return True
    if x < 0:
        return False
    if len(moves) == 0:
        return False

    if knapsack(x - moves[0], moves[1:]):
        return True

    if knapsack(x, moves[1:]):
        return True

    return False

def split_moves(s):
    moves = [[0], []]
    i = 0
    j = 0

    for c in s:
        if c == 'F':
            moves[i][-1] += 1
        else:
            i = 1 - i
            moves[i].append(0)

    return moves

main()

Submission status: Runtime Error

Solution code:
def main():
    s = input()
    x, y = map(int, input().split())
    if solve(s, x, y):
        print('Yes')
    else:
        print('No')

def solve(s, x, y):
    moves = split_moves(s)
    if not match(x - moves[0][0], moves[0][1:]):
        return False
    if not match(y, moves[1]):
        return False

    return True

def match(x, moves):
    s = sum(moves)
    if x > s:
        return False

    if (s - x) % 2 != 0:
        return False

    return knapsack((s - x) // 2, moves)

def knapsack(x, moves):
    if x == 0:
        return True
    if x < 0:
        return False
    if len(moves) == 0:
        return False

    if knapsack(x - moves[0], moves[1:]):
        return True

    if knapsack(x, moves[1:]):
        return True

    return False

def split_moves(s):
    moves = [[0], []]
    i = 0
    j = 0

    for c in s:
        if c == 'F':
            moves[i][-1] += 1
        else:
            i = 1 - i
            moves[i].append(0)

    return moves

main()

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
count = 0
d = []
for i in range(len(s)):
    if s[i] == 'F':
        count += 1
    else:
        d.append(count)
        count = 0
if count != 0:
    d.append(count)

dx = [d[i] for i in range(len(d)) if i%2==0]
dy = [d[i] for i in range(len(d)) if i%2==1]
if len(dx) == 0:
    dx = [0]
if len(dy) == 0:
    dy = [0]
dpx = [dx[0]]
dpy = [dy[0],-dy[0]]
for i in range(len(dx)-1):
    trans = set()
    for j in range(len(dpx)):
        trans.add(dpx[j]+dx[i+1])
        trans.add(dpx[j]-dx[i+1])
    dpx = list(trans)
for i in range(len(dy)-1):
    trans = set()
    for j in range(len(dpy[1])):
        trans.add(dpy[1][j]+dy[i+1])
        trans.add(dpy[1][j]-dy[i+1])
    dpy = list(trans)
ans = (x in dpx)&(y in dpy)

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

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
count = 0
d = []
for i in range(len(s)):
    if s[i] == 'F':
        count += 1
    else:
        d.append(count)
        count = 0
if count != 0:
    d.append(count)

dx = [d[i] for i in range(len(d)) if i%2==0]
dy = [d[i] for i in range(len(d)) if i%2==1]
if len(dx) == 0:
    dx = [0]
if len(dy) == 0:
    dy = [0]
dpx = [[] for i in range(len(dx))]
dpx[0] = [dx[0]]
dpy = [[] for i in range(len(dy))]
dpy[0] = [dy[0],-dy[0]]
for i in range(len(dx)-1):
    trans = set()
    for j in range(len(dpx[i])):
        trans.add(dpx[i][j]+dx[i+1])
        trans.add(dpx[i][j]-dx[i+1])
    dpx[i+1] = trans
for i in range(len(dy)-1):
    trans = set()
    for j in range(len(dpy[i])):
        trans.add(dpy[i][j]+dy[i+1])
        trans.add(dpy[i][j]-dy[i+1])
    dpy[i+1] = trans
ans = (x in dpx[-1])&(y in dpy[-1])

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

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
count = s.count('F')
ans = abs(x)+abs(y) <= count
def bfs(x,y,s,count):
    if count < abs(x)+abs(y):
        return False
    elif x==0 and y==0 and s == '':
        return True
    else:
        if s[0] == 'F':
            x -= 1
            s = s[1:]
            count -= 1
            return bfs(x,y,s,count)
        else:
            s = s[1:]
            return bfs(y,-x,s,count) or bfs(-y,x,s,count)
ans = bfs(x,y,s,count)
if ans:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
def search(keys,dic,now,goal):
    if now==len(keys):
        if goal==0:
            return True
        else:
            return False
    k=keys[now]
    for i in range(dic[k]+1):
        if search(keys,dic,now+1,goal-k*i+k*(dic[k]-i)):
            return True
    return False

s=input()+'T'
x,y=list(map(int,input().split()))
xlist=[0 for _ in range(8000)]
ylist=[0 for _ in range(8000)]
flag='x+'
ini=0
tmp=0
for c in s:
    if c =='F':
        tmp+=1
    else:
        if flag=='x':
            xlist[tmp]+=1
        elif flag=='y':
            ylist[tmp]+=1
        else:
            ini=tmp
        tmp=0
        if flag=='y':
            flag='x'
        else:
            flag='y'
xlist[0]=0
ylist[0]=0
xkey=[]
ykey=[]
for i in range(8000):
    if xlist[i]>0:
        xkey.append(i)
    if ylist[i]>0:
        ykey.append(i)
xkey.inverse()
ykey.inverse()
if search(xkey,xlist,0,x-ini) and search(ykey,xlist,0,y):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

a = []
t = 0
for s in S:
    if s == "F":
        t += 1
    else:
        a.append(t)
        t = 0
a.append(t)

if a == []:
    if x == y == 0:
        print("Yes")
        exit(0)
    else:
        print("No")
        exit(0)

d = [[a[0],0]]
for k in range(1,len(a)):
    n = []
    if k%2 == 1:
        for e in d:
            n.append([e[0],e[1]+a[k]])
            n.append([e[0],e[1]-a[k]])
    else:
        for e in d:
            n.append([e[0]+a[k],e[1]])
            n.append([e[0]-a[k],e[1]])
    d = list(set(n))

print("Yes" if [x,y] in d else "No")