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:
s=input()
x,y=[int(i) for i in input().split()]
count=0
x_v=[]
y_v=[]

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        

x_check=0
dp_x=[[0 for i in range(4*sum(x_v)+2)] for j in range(len(x_v))]
dp_x[0][2*sum(x_v)+x_v[0]]=1

for i in range(len(x_v)-1):
    for j in range(4*sum(x_v)+2):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][j-x_v[i+1]]=1,1
if sum(x_v)>=abs(x):
    if dp_x[len(x_v)-1][sum(x_v)+x]==1:
        x_check=1


y_check=0
dp_y=[[0 for i in range(4*sum(y_v)+2)] for j in range(len(y_v))]
dp_y[0][2*sum(y_v)+y_v[0]]=1
dp_y[0][2*sum(y_v)-y_v[0]]=1

for i in range(len(y_v)-1):
    for j in range(2*sum(y_v)+2):
        if dp_y[i][j]==1:
            dp_y[i+1][j+y_v[i+1]], dp_y[i+1][j-y_v[i+1]]=1,1
if sum(y_v)>=abs(y):
    if dp_y[len(y_v)-1][sum(y_v)+y]==1:
        y_check=1


if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s=input()
x,y=[int(i) for i in input().split()]
count=0
x_v=[]
y_v=[]

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        

x_check=0
dp_x=[[0 for i in range(2*sum(x_v)+2)] for j in range(len(x_v))]
dp_x[0][sum(x_v)+x_v[0]]=1

for i in range(len(x_v)-1):
    for j in range(2*sum(x_v)+2):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][j-x_v[i+1]]=1,1
if sum(x_v)>=abs(x):
    if dp_x[len(x_v)-1][sum(x_v)+x]==1:
        x_check=1


y_check=0
dp_y=[[0 for i in range(2*sum(y_v)+2)] for j in range(len(y_v))]
dp_y[0][sum(y_v)+y_v[0]]=1
dp_y[0][sum(y_v)-y_v[0]]=1

for i in range(len(y_v)-1):
    for j in range(2*sum(y_v)+2):
        if dp_y[i][j]==1:
            dp_y[i+1][j+y_v[i+1]], dp_y[i+1][j-y_v[i+1]]=1,1
if sum(y_v)>=abs(y):
    if dp_y[len(y_v)-1][sum(y_v)+y]==1:
        y_check=1


if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s=input()
x,y=[int(i) for i in input().split()]
count=0
x_v=[]
y_v=[]

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        

x_check=0
dp_x=[[0 for i in range(2*sum(x_v)+20)] for j in range(len(x_v))]
dp_x[0][sum(x_v)+10+x_v[0]]=1

for i in range(len(x_v)-1):
    for j in range(2*sum(x_v)+20):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][j-x_v[i+1]]=1,1
if sum(x_v)>=abs(x):
    if dp_x[len(x_v)-1][sum(x_v)+10+x]==1:
        x_check=1


y_check=0
dp_y=[[0 for i in range(2*sum(y_v)+20)] for j in range(len(y_v))]
dp_y[0][sum(y_v)+10+y_v[0]]=1
dp_y[0][sum(y_v)+10-y_v[0]]=1

for i in range(len(y_v)-1):
    for j in range(2*sum(y_v)+20):
        if dp_y[i][j]==1:
            dp_y[i+1][j+y_v[i+1]], dp_y[i+1][j-y_v[i+1]]=1,1
if sum(y_v)>=abs(y):
    if dp_y[len(y_v)-1][sum(y_v)+10+y]==1:
        y_check=1


if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s=input()
x,y=[int(i) for i in input().split()]
count=0
x_v=[]
y_v=[]

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        

x_check=0
dp_x=[[0 for i in range(2*sum(x_v)+20)] for j in range(len(x_v))]
dp_x[0][sum(x_v)+10+x_v[0]]=1

for i in range(len(x_v)-1):
    for j in range(2*sum(x_v)+20):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][j-x_v[i+1]]=1,1
if sum(x_v)>abs(x):
    if dp_x[len(x_v)-1][sum(x_v)+10+x]==1:
        x_check=1


y_check=0
dp_y=[[0 for i in range(2*sum(y_v)+20)] for j in range(len(y_v))]
dp_y[0][sum(y_v)+10+y_v[0]]=1
dp_y[0][sum(y_v)+10-y_v[0]]=1

for i in range(len(y_v)-1):
    for j in range(2*sum(y_v)+20):
        if dp_y[i][j]==1:
            dp_y[i+1][j+y_v[i+1]], dp_y[i+1][j-y_v[i+1]]=1,1
if sum(y_v)>abs(y):
    if dp_y[len(y_v)-1][sum(y_v)+10+y]==1:
        y_check=1


if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s=input()
x,y=[int(i) for i in input().split()]
count=0
x_v=[]
y_v=[]

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        

x_check=0
dp_x=[[0 for i in range(2*sum(x_v)+20)] for j in range(len(x_v))]
dp_x[0][sum(x_v)+10+x_v[0]]=1

for i in range(len(x_v)-1):
    for j in range(2*sum(x_v)+20):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][j-x_v[i+1]]=1,1

if dp_x[len(x_v)-1][sum(x_v)+10+x]==1:
    x_check=1


y_check=0
dp_y=[[0 for i in range(2*sum(y_v)+20)] for j in range(len(y_v))]
dp_y[0][sum(y_v)+10+y_v[0]]=1
dp_y[0][sum(y_v)+10-y_v[0]]=1

for i in range(len(y_v)-1):
    for j in range(2*sum(y_v)+20):
        if dp_y[i][j]==1:
            dp_y[i+1][j+y_v[i+1]], dp_y[i+1][j-y_v[i+1]]=1,1

if dp_y[len(y_v)-1][sum(y_v)+10+y]==1:
    y_check=1


if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s=input()
x,y=[int(i) for i in input().split()]
count=0
x_v=[]
y_v=[]

dir=1
for i in range(len(s)):
    if s[i]=="F":
        count=count+1
    else:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0
    if i==len(s)-1:
        if dir==1:
            x_v.append(count)
            dir=0
            count=0
        else:
            y_v.append(count)
            dir=1
            count=0        

x_check=0
dp_x=[[0 for i in range(2*sum(x_v)+2)] for j in range(len(x_v))]
dp_x[0][sum(x_v)+x_v[0]]=1

for i in range(len(x_v)-1):
    for j in range(2*sum(x_v)+2):
        if dp_x[i][j]==1:
            dp_x[i+1][j+x_v[i+1]], dp_x[i+1][j-x_v[i+1]]=1,1

if dp_x[len(x_v)-1][sum(x_v)+x]==1:
    x_check=1


y_check=0
dp_y=[[0 for i in range(2*sum(y_v)+2)] for j in range(len(y_v))]
dp_y[0][sum(y_v)+y_v[0]]=1
dp_y[0][sum(y_v)-y_v[0]]=1

for i in range(len(y_v)-1):
    for j in range(2*sum(y_v)+2):
        if dp_y[i][j]==1:
            dp_y[i+1][j+y_v[i+1]], dp_y[i+1][j-y_v[i+1]]=1,1

if dp_y[len(y_v)-1][sum(y_v)+y]==1:
    y_check=1


if x_check==1 and y_check==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys
def check(i,a):
    b = {}
    for j in a:
        if j == i:
            return True
        for k in b.keys():
            if k+j == i:
                return True
            b[k+j]=True
        b[j]=True
    print(a)
    print(b)
    return False


s = input()
x,y = [int(x) for x in input().split()]

xf = []
yf = []

now = xf
t = 0
for i in s:
    if i == 'F':
        t += 1
    else:
        if t != 0:
            now.append(t)
            t = 0
        if now == xf:
            now = yf
        else:
            now = xf
now.append(t)

xt = sum(xf)
xb = False
if xt == x:
    xb = True
elif x > 0:
    if xt < x:
        print('No')
        sys.exit()
    elif len(xf)>=2:
        xt = x - xt
        xb = check(xt,xf[1:])
else:
    xt = xf[0] - sum(xf[1:])
    if xt == x:
        xb = True
    else:
        if xt < x:
            print('No')
            sys.exit()
        elif len(xf)>=2:
            xt = abs(x - xt)
            xb = check(xt,xf[1:])
if not xb:
    print('No')
    sys.exit()


yt = sum(yf)
yb = False
if yt == y:
    yb = True
elif y > 0:
    if yt < y:
        print('No')
        sys.exit()
    elif len(yf)>=2:
        yt = y - yt
        yb = check(yt,yf)
else:
    yt = -yt
    if yt == y:
        yb = True
    else:
        if yt < y:
            print('No')
            sys.exit()
        elif len(yf)>=2:
            yt = abs(y - yt)
            yb = check(yt,yf)
if not yb:
    print('No')
    sys.exit()

if xb and yb:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys
def check(i,a):
    b = {}
    for j in a:
        for k in b.keys():
            if k+j == i:
                return True
            b[k+j]=True
    return False


s = input()
x,y = [int(x) for x in input().split()]

xf = []
yf = []

now = xf
t = 0
for i in s:
    if i == 'F':
        t += 1
    else:
        if t != 0:
            now.append(t)
            t = 0
        if now == xf:
            now = yf
        else:
            now = xf
now.append(t)
xf.sort(reverse=True)
yf.sort(reverse=True)

xt = sum(xf)
xb = False
if xt == x:
    xb = True
elif x > 0:
    if xt < x:
        print('No')
        sys.exit()
    elif len(xf)>=2:
        xt = x - xt
        xb = check(xt,xf[1:])
else:
    xt = xf[0] - sum(xf[1:])
    if xt == x:
        xb = True
    else:
        if xt < x:
            print('No')
            sys.exit()
        elif len(xf)>=2:
            xt = abs(x - xt)
            xb = check(xt,xf[1:])
if not xb:
    print('No')
    sys.exit()


yt = sum(yf)
yb = False
if yt == y:
    yb = True
elif y > 0:
    if yt < y:
        print('No')
        sys.exit()
    elif len(yf)>=2:
        yt = y - yt
        yb = check(yt,yf)
else:
    yt = -yt
    if yt == y:
        yb = True
    else:
        if yt < y:
            print('No')
            sys.exit()
        elif len(yf)>=2:
            yt = abs(y - yt)
            yb = check(yt,yf)
if not yb:
    print('No')
    sys.exit()

if xb and yb:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
from operator import add
debug = False
if debug:
    s = "FTFFTFFF"
    x, y = [4, 2]
else:
    s = input()
    x, y = list(map(int, input().split()))

s = list(s)
xys = [(1, 0), (0, 1), (-1, 0), (0, -1)]


def search(xy, idx, s):
    if xy == [x, y] and len(s) == 0:
        return True

    if len(s) == 0:
        return False
    m = s[0]
    if m == "F":
        z = list(map(add, xy, xys[idx]))
        return search(z, idx, s[1:])
    elif m == "T":
        return search(xy, (idx + 1) % 4, s[1:]) or search(xy, (idx - 1) % 4, s[1:])


print("Yes" if search((0, 0), 0, s) else "No")

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# coding: utf-8

def no():
    print("No")
    return

def shift(i):
    return i+8001

def main():
    s = input()
    x, y = list(map(int, input().split()))
    x_start = 0
    x_count = 0
    y_count = 0
    t_count = 0
    f_count = 0
    x_dirs = []
    y_dirs = []
    is_x = True # xを向いてるか
    f_before_t = 0
    t_exist = False
    for c in s:
        if c == "T":
            t_count += 1
            if f_count > 0:
                if is_x and not t_exist:
                    x_dirs.append(f_count)
                else:
                    y_dirs.append(f_count)
                f_count = 0
            t_exist = True
            continue
        f_count += 1
        if not t_exist:
            x_start += 1
            f_before_t += 1
        if t_count % 2 == 0:
            # 向いている方向に進む
            if is_x:
                x_count += 1
            else:
                y_count += 1
        else:
            if is_x:
                y_count += 1
            else:
                x_count += 1
            is_x = not is_x
        t_count = 0
    if f_count > 0:
        if is_x:
            x_dirs.append(f_count)
        else:
            y_dirs.append(f_count)
    if (x % 2) != (x_count % 2):
        return no()
    if abs(x) > x_count:
        return no()
    if (y % 2) != (y_count % 2):
        return no()
    if abs(y) > y_count:
        return no()
    if (x_count - f_before_t*2) < x*-1:
        return no()


    memo_x = [[False for _ in range(16001)] for _ in range(len(x_dirs)+1)]
    memo_y = [[False for _ in range(16001)] for _ in range(len(y_dirs)+1)]
    memo_x[0][shift(x_start)] = True
    memo_y[0][0] = True

    for i, dx in enumerate(x_dirs):
        for j in range(16001):
            if memo_x[i][j]:
                memo_x[i+1][j-dx] = True
                memo_x[i+1][j+dx] = True
    for i, dy in enumerate(y_dirs):
        for j in range(16001):
            if memo_y[i][j]:
                memo_y[i+1][j-dy] = True
                memo_y[i+1][j+dy] = True
    if not memo_x[len(x_dirs)][shift(x)]:
        return no()
    if not memo_y[len(y_dirs)][shift(y)]:
        return no()
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
s = list(input())
x, y = map(int, input().split())

X = [0] * 16001
Y = [0] * 16001

X[8000] = Y[8000] = 0
isx = 1
tcnt = 0
fcnt = 0
for i in range(len(s)):
    if s[i] == 'T':
        for j in range(len(X)):
            if isx == 1:
                if tcnt == 0:
                    X[8000 + fcnt] = tcnt + 1
                    break
                if X[j] == tcnt:
                    X[j + fcnt] = X[j - fcnt] = tcnt + 1
            else:
                if X[j] == tcnt:
                    X[j] = tcnt + 1
        for j in range(len(Y)):
            if isx == 0:
                if Y[j] == tcnt:
                    Y[j + fcnt] = Y[j - fcnt] = tcnt + 1
            else:
                if Y[j] == tcnt:
                    Y[j] = tcnt + 1
        isx ^= 1
        tcnt += 1
        fcnt = 0
    else:
        fcnt += 1

if s[-1] == 'F':
    for j in range(len(X)):
        if isx == 1:
            if tcnt == 0:
                X[8000 + fcnt] = tcnt + 1
                break
            if X[j] == tcnt:
                X[j + fcnt] = X[j - fcnt] = tcnt + 1
        else:
            if X[j] == tcnt:
                X[j] = tcnt + 1
    for j in range(len(Y)):
        if isx == 0:
            if Y[j] == tcnt:
                Y[j + fcnt] = Y[j - fcnt] = tcnt + 1
        else:
            if Y[j] == tcnt:
                Y[j] = tcnt + 1
    isx ^= 1
    tcnt += 1
    fcnt = 0

print('Yes' if (X[8000 + x] == tcnt and Y[8000 + y] == tcnt) else 'No')

Submission status: Runtime Error

Solution code:
from operator import add
debug = False
if debug:
    s = "FTFFTFFF"
    x, y = [4, 2]
else:
    s = input()
    x, y = list(map(int, input().split()))

s = list(s)
xys = [(1, 0), (0, 1), (-1, 0), (0, -1)]


def search(xy, idx, s):
    if xy == [x, y] and len(s) == 0:
        return True

    if len(s) == 0:
        return False
    m = s[0]
    if m == "F":
        z = list(map(add, xy, xys[idx]))
        if xy == 0:
            return search(z, idx, s[1:])
        else:
            return search(z, idx, s[1:])
    elif m == "T":
        return search(xy, idx + 1, s[1:]) or search(xy, idx - 1, s[1:])


print("Yes" if search((0, 0), 0, s) else "No")

Submission status: Runtime Error

Solution code:
from operator import add
debug = False
if debug:
    s = "FTFFTFFF"
    x, y = [4, 2]
else:
    s = input()
    x, y = list(map(int, input().split()))

s = list(s)
xys = [(1, 0), (0, 1), (-1, 0), (0, -1)]


def search(xy, idx, s):
    if xy == [x, y]:
        return True

    if len(s) == 0:
        return False
    m = s[0]
    if m == "F":
        z = list(map(add, xy, xys[idx]))
        if xy == 0:
            return search(z, idx, s[1:])
        else:
            return search(z, idx, s[1:])
    elif m == "T":
        return search(xy, idx + 1, s[1:]) or search(xy, idx - 1, s[1:])


print("Yes" if search((0, 0), 0, s) else "No")

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)
def check(i,t,a):
    if i == t:
        return True
    for j in range(a):
        if i == t+a[j]:
            return True
        elif i < t+a[j]:
            return False
        else:
            return check(i,t+a[j],a[:j]+a[j+1:])
    return False



s = input()
x,y = [int(x) for x in input().split()]

xf = []
yf = []

now = xf
t = 0
for i in s:
    if i == 'F':
        t += 1
    else:
        if t != 0:
            now.append(t)
            t = 0
        if now == xf:
            now = yf
        else:
            now = xf
now.append(t)


xt = sum(xf)
xb = False
if xt == x:
    xb = True
elif x > 0:
    if xt < x:
        print('No')
        sys.exit()
    elif len(xf)>=2:
        xt = x - xt
        xb = check(xt,0,xf[1:])
else:
    xt = xf[0] - sum(xf[1:])
    if xt == x:
        xb = True
    else:
        if xt < x:
            print('No')
            sys.exit()
        elif len(xf)>=2:
            xt = abs(x - xt)
            xb = check(xt,0,xf[1:])
if not xb:
    print('No')
    sys.exit()


yt = sum(yf)
yb = False
if yt == y:
    yb = True
elif y > 0:
    if yt < y:
        print('No')
        sys.exit()
    elif len(yf)>=2:
        yt = y - yt
        yb = check(yt,0,yf)
else:
    yt = -yt
    if yt == y:
        yb = True
    else:
        if yt < y:
            print('No')
            sys.exit()
        elif len(yf)>=2:
            yt = abs(y - yt)
            yb = check(yt,0,yf)
if not yb:
    print('No')
    sys.exit()

if xb and yb:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys

def check(i,t,a):
    if i == t:
        return True
    for j in range(a):
        if i == t+a[j]:
            return True
        elif i < t+a[j]:
            return False
        else:
            return check(i,t+a[j],a[:j]+a[j+1:])
    return False


s = input()
x,y = [int(x) for x in input().split()]

xf = []
yf = []

now = xf
t = 0
for i in s:
    if i == 'F':
        t += 1
    else:
        if t != 0:
            now.append(t)
            t = 0
        if now == xf:
            now = yf
        else:
            now = xf
now.append(t)


xt = sum(xf)
xb = False
if xt == x:
    xb = True
elif x > 0:
    if xt < x:
        print('No')
        sys.exit()
    elif len(xf)>=2:
        xt = x - xt
        xb = check(xt,0,xf[1:])
else:
    xt = xf[0] - sum(xf[1:])
    if xt == x:
        xb = True
    else:
        if xt < x:
            print('No')
            sys.exit()
        elif len(xf)>=2:
            xt = abs(x - xt)
            xb = check(xt,0,xf[1:])
if not xb:
    print('No')
    sys.exit()


yt = sum(yf)
yb = False
if yt == y:
    yb = True
elif y > 0:
    if yt < y:
        print('No')
        sys.exit()
    elif len(yf)>=2:
        yt = y - yt
        yb = check(yt,0,yf)
else:
    yt = -yt
    if yt == y:
        yb = True
    else:
        if yt < y:
            print('No')
            sys.exit()
        elif len(yf)>=2:
            yt = abs(y - yt)
            yb = check(yt,0,yf)
if not yb:
    print('No')
    sys.exit()

if xb and yb:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys


def check(i,t,a):
    if i == t:
        return True
    for j in range(a):
        if i == t+a[j]:
            return True
        elif i < t+a[j]:
            return False
        else:
            return check(i,t+a[j],a[:j-1]+a[j+1:])
    return False



s = input()
x,y = [int(x) for x in input().split()]

xf = []
yf = []

now = xf
t = 0
for i in s:
    if i == 'F':
        t += 1
    else:
        if t != 0:
            now.append(t)
            t = 0
        if now == xf:
            now = yf
        else:
            now = xf
now.append(t)


xt = sum(xf)
xb = False
if xt == x:
    xb = True
elif x > 0:
    if xt < x:
        print('No')
        sys.exit()
    elif len(xf)>=2:
        xt = x - xt
        xb = check(xt,0,xf[1:])
else:
    xt = xf[0] - sum(xf[1:])
    if xt == x:
        xb = True
    else:
        if xt < x:
            print('No')
            sys.exit()
        elif len(xf)>=2:
            xt = abs(x - xt)
            xb = check(xt,0,xf[1:])
if not xb:
    print('No')
    sys.exit()


yt = sum(yf)
yb = False
if yt == y:
    yb = True
elif y > 0:
    if yt < y:
        print('No')
        sys.exit()
    elif len(yf)>=2:
        yt = y - yt
        yb = check(yt,0,yf)
else:
    yt = -yt
    if yt == y:
        yb = True
    else:
        if yt < y:
            print('No')
            sys.exit()
        elif len(yf)>=2:
            yt = abs(y - yt)
            yb = check(yt,0,yf)
if not yb:
    print('No')
    sys.exit()

if xb and yb:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys


def check(i,t,a):
    if i == t:
        return True
    for j in range(a):
        if i == t+a[j]:
            return True
        elif i < t+a[j]:
            return False
        else:
            return check(i,t+a[j],a[:j-1]+a[j+1:])




s = input()
x,y = [int(x) for x in input().split()]

xf = []
yf = []

now = xf
t = 0
for i in s:
    if i == 'F':
        t += 1
    else:
        now.append(t)
        t = 0
        if now == xf:
            now = yf
        else:
            now = xf
now.append(t)


xt = sum(xf)
xb = False
if xt == x:
    xb = True
elif x > 0:
    if xt < x:
        print('No')
        sys.exit()
    elif len(xf)>=2:
        xt = x - xt
        xb = check(xt,0,xf[1:])
else:
    xt = xf[0] - sum(xf[1:])
    if xt == x:
        xb = True
    else:
        print(xt)
        if xt < x:
            print('No')
            sys.exit()
        elif len(xf)>=2:
            xt = abs(x - xt)
            xb = check(xt,0,xf[1:])
if not xb:
    print('No')
    sys.exit()


yt = sum(yf)
yb = False
if yt == y:
    yb = True
elif y > 0:
    if yt < y:
        print('No')
        sys.exit()
    elif len(yf)>=2:
        yt = y - yt
        yb = check(yt,0,yf)
else:
    yt = -yt
    if yt == y:
        yb = True
    else:
        if yt < y:
            print('No')
            sys.exit()
        elif len(yf)>=2:
            yt = abs(y - yt)
            yb = check(yt,0,yf)
if not yb:
    print('No')
    sys.exit()

if xb and yb:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
from collections import deque
S = input()
x, y = map(int, input().split(' '))

move = [(1, 0), (0, 1), (-1, 0), (0, -1)]
direction = 0

position = set((0, 0))
state = [((0, 0), 0)]

can_move = False
idx = 0

for i, s in enumerate(S):
    rest_inst_num = len(S) - (i)
    next_position = set()
    next_state = []
    for p, d in state:
        xx, yy = p
        dist2goal = abs(xx - x) + abs(yy - y)
        if dist2goal > rest_inst_num:
            continue
        if s == 'T':
            next_position.add(p)
            next_state.append((p, d + 1))
            next_state.append((p, d - 1))
        else:
            mxx, myy = move[d]
            np = (xx + mxx, yy + myy)
            next_position.add(np)
            next_state.append((np, d))
    position = next_position
    state = next_state

if (x, y) in position:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
from collections import deque
S = input()
x, y = map(int, input().split(' '))

move = [(1, 0), (0, 1), (-1, 0), (0, -1)]
direction = 0

position = set((0, 0))
state = [((0, 0), 0)]

can_move = False
idx = 0

for i, s in enumerate(S):
    rest_inst_num = len(S) - (i + 1)
    next_position = set()
    next_state = []
    for p, d in state:
        xx, yy = p
        dist2goal = abs(xx - x) + abs(yy - y)
        if dist2goal > rest_inst_num:
            continue
        if s == 'T':
            next_position.add(p)
            next_state.append((p, d + 1))
            next_state.append((p, d - 1))
        else:
            mxx, myy = move[d]
            np = (xx + mxx, yy + myy)
            next_position.add(np)
            next_state.append((np, d))
    position = next_position
    state = next_state
    snum += len(state)

if (x, y) in position:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
from collections import deque
S = input()
x, y = map(int, input().split(' '))

move = [(1, 0), (0, 1), (-1, 0), (0, -1)]
direction = 0

position = set((0, 0))
state = [((0, 0), 0)]

can_move = False
idx = 0

for s in S:
    next_position = set()
    next_state = []
    for p, d in state:
        if s == 'T':
            next_position.add(p)
            next_state.append((p, d + 1))
            next_state.append((p, d - 1))
        else:
            xx, yy = p
            mxx, myy = move[d]
            np = (xx + mxx, yy + myy)
            next_position.add(np)
            next_state.append((np, d))
    position = next_position
    state = next_state

if (x, y) in position:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s=input().strip()
x,y=[int(i) for i in input().split()]

# print(s,x,y)
F_list=s.split("T")
# print(F_list)
x_F_num=[]
y_F_num=[]
for i in range(len(F_list)):
    if i%2==0:
        x_F_num.append(len(F_list[i]))
    else:
        y_F_num.append(len(F_list[i]))
# print(x_F_num,y_F_num)

#x
ikeru=[]
next_ikeru=[]
ikeru.append(x_F_num[0])
for i in range(1,len(x_F_num)):
    num=x_F_num[i]
    for j in ikeru:
        next_ikeru.append(j+num)
        next_ikeru.append(j-num)
    ikeru=list(set(next_ikeru))
x_ok=x in ikeru
#y
ikeru=[]
next_ikeru=[]
ikeru.append(y_F_num[0])
ikeru.append(0-y_F_num[0])
for i in range(1,len(y_F_num)):
    num=y_F_num[i]
    for j in ikeru:
        next_ikeru.append(j+num)
        next_ikeru.append(j-num)
    ikeru=list(set(next_ikeru))
y_ok=y in ikeru

if x_ok==True and y_ok==True:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s = input()
x, y = map(int, input().split())
dic = {"U": (1, 0), "R": (0, 1), "D": (-1, 0), "L": (0, -1)}
rec = []


def dfs(x1, y1, pos, k):
    if k == len(s):
        if (x1, y1) not in rec:
            rec.append((x1, y1))
        return
    else:
        if s[k] == "F":
            nx, ny = x1 + dic[pos][0], y1 + dic[pos][1]
            dfs(nx, ny, pos, k + 1)
        else:
            if pos == "U" or pos == "D":
                dfs(x1, y1, "R", k + 1)
                dfs(x1, y1, "L", k + 1)
            else:
                dfs(x1, y1, "U", k + 1)
                dfs(x1, y1, "D", k + 1)


dfs(0, 0, "R", 0)
if (y, x) in rec:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = input()
x, y = map(int, input().split())
sx, sy = 0, 0
dic = {"U":(1,0), "R":(0, 1), "D":(-1,0), "L":(0, -1)}
rec = []


def dfs(x1, y1, pos, k):
    if k == len(s):
        rec.append((x1, y1))
        return
    else:
        if s[k] == "F":
            nx, ny = x1 + dic[pos][0], y1 + dic[pos][1]
            dfs(nx, ny, pos, k + 1)
        else:
            if pos == "U" or pos == "D":
                dfs(x1, y1, "R", k + 1)
                dfs(x1, y1, "L", k + 1)
            else:
                dfs(x1, y1, "U", k + 1)
                dfs(x1, y1, "D", k + 1)


dfs(0, 0, "R", 0)
if (y, x) in rec:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = input()
x, y = [int(x) for x in input().split()]

d = (
    (1, 0),
    (0, 1),
    (-1, 0),
    (0, -1),
)

def next_dr(dr):
    def fix(dr):
        if dr == -1:
            return 3
        if dr == 4:
            return 0
        return dr
    return fix(dr - 1), fix(dr + 1)

def dfs(s, a, b, dr):
    # print("===")
    # print(s)
    # print(a, b)
    # print(dr)
    # print(x == a and y == b)

    if s == '':
        return x == a and y == b

    if s[0] == 'F':
        dx, dy = d[dr]
        a += dx
        b += dy
        return dfs(s[1:], a, b, dr)
    else:
        next_dr1, next_dr2 = next_dr(dr)
        return dfs(s[1:], a, b, next_dr1) or dfs(s[1:], a, b, next_dr2)

ans = "Yes" if dfs(s, 0, 0, 0) else "No"
print(ans)