Problem:


Score : 500 points

Problem Statement

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

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

F : Move in the current direction by distance 1.

T : Turn 90 degrees, either clockwise or counterclockwise.

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

Constraints

s consists of F and T.

1 \leq |s| \leq 8 000

x and y are integers.

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

Input

Input is given from Standard Input in the following format:

s
x y

Output

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

Sample Input 1

FTFFTFFF
4 2

Sample Output 1

Yes

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

Sample Input 2

FTFFTFFF
-2 -2

Sample Output 2

Yes

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

Sample Input 3

FF
1 0

Sample Output 3

No

Sample Input 4

TF
1 0

Sample Output 4

No

Sample Input 5

FFTTFF
0 0

Sample Output 5

Yes

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

Sample Input 6

TTTT
1 0

Sample Output 6

No



Sample input:
FTFFTFFF
4 2


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
s = str(input())
x,y = map(int,input().split())
n = len(s)
dx = []
dy = []
if s[0] == 'T':
	dx.append(0)
i = 0
counter = 0
check = 1
while i < n:
	if s[i] == 'T' and check == 1:
		dx.append(counter)
		check = check * -1
		counter = 0
	elif s[i] == 'T' and check == -1:
		dy.append(counter)
		check = check * -1
		counter = 0
	elif i == n-1 and check == 1:
		dx.append(counter+1)
	elif i == n-1 and check == -1:
		dy.append(counter+1)
	else:
		counter += 1
	i += 1

nx = len(dx)
xtable = [[False for i in range(2*n+1)] for i in range(nx+1)]
#横軸がx座標(-n<=x<=n)、縦軸が操作回数
xtable[0][n] = True
for i in range(1,nx+1):
	for k in range(2*n+1):
		if k+dx[i-1] <= 2*n and k-dx[i-1] >= 0:
			if xtable[i-1][k+dx[i-1]] == True or xtable[i-1][k-dx[i-1]] == True:
				xtable[i][k] = True
		elif k+dx[i-1] <= 2*n:
			if xtable[i-1][k+dx[i-1]] == True:
				xtable[i][k] = True
		elif k-dx[i-1] >= 0:
			if xtable[i-1][k-dx[i-1]] == True:
				xtable[i][k] = True

ny = len(dy)
ytable = [[False for i in range(2*n+1)] for i in range(ny+1)]
#横軸がy座標(-n<=y<=n)、縦軸が操作回数
ytable[0][n] = True
for i in range(1,ny+1):
	for k in range(2*n+1):
		if k+dy[i-1] <= 2*n and k-dy[i-1] >= 0:
			if ytable[i-1][k+dy[i-1]] == True or ytable[i-1][k-dy[i-1]] == True:
				ytable[i][k] = True
		elif k+dy[i-1] <= 2*n:
			if ytable[i-1][k+dy[i-1]] == True:
				ytable[i][k] = True
		elif k-dy[i-1] >= 0:
			if ytable[i-1][k-dy[i-1]] == True:
				ytable[i][k] = True

if xtable[nx][x+n] == True and ytable[ny][y+n] == True:
	print('Yes')
else:
	print('No')

Submission status: Wrong Answer

Solution code:
def ans():
    s = input()
    x, y = map(int, input().split())
    # dpx = [[0] * (len(s) * 2)] * abs(x + 1)
    # dpy = [[0] * (len(s) * 2)] * abs(y + 1)
    dpx = [0] * (len(s) + 1)
    dpy = [0] * (len(s) + 1)
    # dpx[0][1] = True
    # dpy[0][1] = True
    dpx[0] = True
    dpy[0] = True
    head = 0
    xcnt = 1
    ycnt = 1
    for i, v in enumerate(s):
        if v == 'F':
            if head == 0:
                dpx[xcnt] = dpx[xcnt - 1]
                xcnt += 1
            else:
                dpy[ycnt] = dpy[ycnt - 1]
                ycnt += 1
        if v == 'T':
            if head == 1:
                head = 0
            else:
                head = 1
    if dpx[abs(x)] and dpy[abs(y)]:
        return print('Yes')
    else:
        return print('No')


ans()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys

s = raw_input().split()[0]
x, y = [int(e) for e in raw_input().split()]
# print s
# print x, y

nF = 0
for c in s:
    if c == 'F':
        nF += 1
nT = len(s) - nF

ans = False

minF = abs(x) + abs(y)
if nF >= minF:
    nF -= minF
    if y > 0:
        nT -=1
        if x > 0:
            pass
        elif x == 0:
            pass
        else:
            nT -= 1
    elif y == 0:
        pass
        if x > 0:
            pass
        elif x == 0:
            pass
        else:
            nT -= 2
    else:
        nT -=1
        if x > 0:
            pass
        elif x == 0:
            pass
        else:
            nT -= 1

    if nT >= 0:
        if (nF & 1) == 0:
            square = (nF/4)*4
            if nT >= square:
                nF -= square
                nT -= (square - 1)
            if nT >= nF:
                ans = True
            
if ans:
    sys.stdout.write('Yes\n')
else:
    sys.stdout.write('No\n')
sys.stdout.flush()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys

s = raw_input().split()[0]
x, y = [int(e) for e in raw_input().split()]
# print s
# print x, y

nF = 0
for c in s:
    if c == 'F':
        nF += 1
nT = len(s) - nF

ans = False

minF = abs(x) + abs(y)
if nF >= minF:
    nF -= minF
    if y > 0:
        nT -=1
        if x > 0:
            pass
        elif x == 0:
            pass
        else:
            nT -= 1
    elif y == 0:
        pass
        if x > 0:
            pass
        elif x == 0:
            pass
        else:
            nT -= 2
    else:
        nT -=1
        if x > 0:
            pass
        elif x == 0:
            pass
        else:
            nT -= 1

    if nT >= 0:
        if (nF & 1) == 0:
            square = (nF/4)*4
            if nT >= square:
                nF -= square
                nT -= (square - 1)
            if nT > nF:
                ans = True
            
if ans:
    sys.stdout.write('Yes\n')
else:
    sys.stdout.write('No\n')
sys.stdout.flush()

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
hL = len(s)
L = 2 * hL

dp = [[False] * (L + 1) for i in range(2)]
ndp = [False] * (L + 1)

def next(i):
    global s
    while i < hL and s[i] != 'T':
        i += 1
    i += 1
    return i

def c(x):
    global hL
    return x + hL

index = 0
t = 0
dp[0][c(0)] = True
dp[1][c(0)] = True
mini, maxi = 0, 1
while index < hL:
    ni = next(index)
    dx, index = ni - index - 1, ni
    for i in range(mini, maxi):
        for j in [-1, 1]:
            if -hL <= i + j * dx <= hL:
                nx = c(i + j * dx)
                ndp[nx] = ndp[nx] or dp[t][c(i)]
    dp[t], ndp = ndp, dp[t]
    for i in range(mini, maxi):
        ndp[c(i)] = False
    mini, maxi = mini - dx, maxi + dx
    t = (t + 1) % 2
print('Yes' if dp[0][c(x)] and dp[1][c(y)] else 'No')

Submission status: Wrong Answer

Solution code:
s = input()
T = len(s)
st = s.split("T")
x, y = map(int, input().split())
XL = []; YL = []
for i in range(len(st)):
    if i % 2 == 0:
        XL.append(len(st[i]))
    else:
        YL.append(len(st[i]))

xx = [[False for j in range(2*T+1)] for i in range(len(XL)+1)]
yy = [[False for j in range(2*T+1)] for i in range(len(YL)+1)]
xx[0][x+T]=True
yy[0][y+T]=True
for i in range(1,len(XL)+1):
    for j in range(2*T+1):
        if j-XL[i-1] < 0:
            xx[i][j]=xx[i-1][j+XL[i-1]]
        elif j+XL[i-1] > 2*T:
            xx[i][j]=xx[i-1][j-XL[i-1]]
        else:
            xx[i][j]=xx[i-1][j-XL[i-1]] or xx[i-1][j+XL[i-1]]

for i in range(1,len(YL)+1):
    for j in range(2*T+1):
        if j-YL[i-1] < 0:
            yy[i][j]=yy[i-1][j+YL[i-1]]
        elif j+YL[i-1] > 2*T:
            yy[i][j]=yy[i-1][j-YL[i-1]]
        else:
            yy[i][j]=yy[i-1][j-YL[i-1]] or yy[i-1][j+YL[i-1]]

if xx[len(XL)][T] and yy[len(YL)][T]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
F_cnt = [len(f) for f in s.split('T')]

x, y = map(int, input().split())
x_all = {0}
y_all = {0}

for i in range(len(F_cnt)):
    x_sub = set()
    y_sub = set()
    if i == 0:
        x_sub = {n + F_cnt[i] for n in x_all}
    elif i % 2 == 0:
        for n in x_all:
            x_sub.add(n + F_cnt[i])
            x_sub.add(n - F_cnt[i])
    else:
        for n in y_all:
            y_sub.add(n + F_cnt[i])
            y_sub.add(n - F_cnt[i])
    x_all |= x_sub
    y_all |= y_sub

if x in x_all and y in y_all:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = input()
F_cnt = [len(f) for f in s.split('T')]

x, y = map(int, input().split())
x_all = {0}
y_all = {0}

for i in range(len(F_cnt)):
    x_posi = set()
    x_nega = set()
    y_posi = set()
    y_nega = set()
    if i == 0:
        x_posi = {n + F_cnt[i] for n in x_all}
    elif i % 2 == 0:
        for n in x_all:
            x_posi.add(n + F_cnt[i])
            x_nega.add(n - F_cnt[i])
    else:
        for n in y_all:
            y_posi.add(n + F_cnt[i])
            y_nega.add(n - F_cnt[i])
    x_all |= x_posi | x_nega
    y_all |= y_posi | y_nega

if x in x_all and y in y_all:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = input()
F_cnt = [len(f) for f in s.split('T')]

x, y = map(int, input().split())
x_all = y_all = {0}

for i in range(len(F_cnt)):
    x_posi = x_nega = y_posi = y_nega = set()
    if i == 0:
        x_posi = {x + F_cnt[i] for x in x_all}
    elif i % 2 == 0:
        x_posi = {x + F_cnt[i] for x in x_all}
        x_nega = {x - F_cnt[i] for x in x_all}
    else:
        y_posi = {y + F_cnt[i] for y in y_all}
        y_nega = {y - F_cnt[i] for y in y_all}
    x_all |= x_posi | x_nega
    y_all |= y_posi | y_nega

if x in x_all and y in y_all:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

F_cnt = [len(f) for f in s.split('T')]

x_max = x_min = y_max = y_min = 0

for i in range(len(F_cnt)):
    if i == 0:
        x_max += F_cnt[i]
    elif i % 2 == 0:
        x_max += F_cnt[i]
        x_min -= F_cnt[i]
    else:
        y_max += F_cnt[i]
        y_min -= F_cnt[i]

if x_min <= x <= x_max and x_max % 2 == x % 2\
   and y_min <= y <= y_max and y_max % 2 == y % 2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc082/tasks/arc087_b

"""
import sys
from sys import stdin
input = stdin.readline


def check_x(forwards):
    n = sum(forwards[::2])      #  x軸方向への最大移動量
    dpx = [False] * (n * 2 + 1) #  真ん中を0として、±両方向のdp領域を確保
    dpx[forwards[0] + n] = True #  最初は0からプラス方向に移動

    for f in forwards[2::2]:
        if f == 0:
            continue
        n_move = dpx[f:] + [False]*f
        p_move = [False]*f + dpx[:-f]
        t = [a or b for a, b in zip(n_move, p_move)]
        dpx = t
    return dpx, n


def check_y(forwards):
    n = sum(forwards[1::2])
    dpy = [False] * (n * 2 + 1)
    dpy[n] = True

    for f in forwards[1::2]:
        if f == 0:
            continue
        n_move = dpy[f:] + [False]*f
        p_move = [False]*f + dpy[:-f]
        t = [a or b for a, b in zip(n_move, p_move)]
        dpy = t
    return dpy, n


def solve(s, gx, gy):
    forwards = [len(x) for x in s.split('T')] #  進む歩数情報の数字に変換
    dpx, zx = check_x(forwards)
    dpy, zy = check_y(forwards)


    if zx//2 < gx:
        return 'No'
    if zy//2 < gy:
        return 'No'

    if dpy[gy + zy] is True and dpx[gx + zx] is True:
        return 'Yes'
    else:
        return 'No'


def main(args):
    s = input().strip()
    gx, gy = map(int, input().split())
    #ns = 'TFFFTFFFTTFTFTTTFTFFFFTFFFFTTFFTTTTFFFFFTFFTTFFFFFTFFFFTFFFFTTFFFTTTTFFTFTFFFFTFFTFFFFFTFFTFFTFFFTTFFFFFFTTFFFFFFFFTTTFFFFTFTTFTTFFTFFFFFFFFFTTTFTTTFFFTTFFTTFFFFFFTTTFFTFFTTTFTTTTFFFFTTFFTFFTFTFTFTFFFFFFFTTTTFFTFTFTTFFTTTTFFTFTFTTFFFFFFFFTFTTTFTFFTFTFFTFFFTTFTFTFFTTTTTTFFFFTFFFFFTFFTTFTTTTTFFTFFFTTFTFFTFFTTTFFFFTFTFFFTTTFTFFFTTFTFTFTFFFFTFTFFFTTTFFTTFFFTFTTTTFFTFFTTTFFTFTFTTFFFFFTFTFFFFFFFTTFFFTFFFFTFFFTFFF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FFTFFFFFTTTTTTTTTFFFFFFFFFTFFFTTTTFTTTTFTFTFFFFFTTTTFFFFTFFFFFFFFTTFTFTFFFTFFTTTTTFTTFFTTTTTFTTFTFTFFTTTFFFFTTFFFTFFTFTFTFFFFTFTFFTTFFTFTFFFTTTTTFTFFFTTTFTTTFTTTFFFFTFTFTTFTFFFFFFTFTTFFTFFTTTFTTTFTTFTTFFFTFFTFTFTFFFFTTTTTTFTFFFFFFFTTTFFTFTFFFFTTFFFTFFTFFTTFTFFFTFFTTTFFFFFFFFFFTTFFTFTFTTFTFTTTFTFFFFTFTTTTFTFTFTFTFFTFFFFTFFTFFFFFFTFTFTFTTFFFTFTFTTFFTFTTTFFFTTFTTTFTFTFFTTFFFFFFFFTTTTTFTFTFFTTTFTFFTTTTTFFFFFTTFFFFFFTTTTFTF'
    # gx, gy = 8000, 100
    ans = solve(s, gx, gy)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc082/tasks/arc087_b

"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline


def check_x(forwards):
    n = sum(forwards[::2])
    dpx = [False] * (n * 2 + 1)
    dpx[forwards[0] + n] = True

    for f in forwards[2::2]:
        if f == 0:
            continue
        n_move = dpx[f:] + [False]*f
        p_move = [False]*f + dpx[:-f]
        t = [a or b for a, b in zip(n_move, p_move)]
        dpx = t
    return dpx, n


def check_y(forwards):
    n = sum(forwards[1::2])
    dpy = [False] * (n * 2 + 1)
    dpy[n] = True

    for f in forwards[1::2]:
        if f == 0:
            continue
        n_move = dpy[f:] + [False]*f
        p_move = [False]*f + dpy[:-f]
        t = [a or b for a, b in zip(n_move, p_move)]
        dpy = t
    return dpy, n


def solve(s, gx, gy):
    n = len(s)
    forwards = [len(x) for x in s.split('T')]

    dpx, zx = check_x(forwards)
    dpy, zy = check_y(forwards)
    try:
        if dpy[gy + zy] is True and dpx[gx + zx] is True:
            return 'Yes'
        else:
            return 'No'
    except:
        return 'No'


def main(args):
    s = input().strip()
    gx, gy = map(int, input().split())
    ans = solve(s, gx, gy)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
def tot(X):
    p=0
    i=0
    ret=[]
    while i < len(X):
        p += X[i]
        ret.append(p)
        i+=1
    return ret

def F(X,x):
    if len(X)==0:
        if x == 0:
            return True
        else:
            return False
    elif len(X)==1:
        if X[0]==x:
            return True
        else:
            return False
    k=len(X)-1
    xtemp=[x]
    xtemp2 = []
    T = tot(X)
    if T[-1]%2 != x%2:
        return False
    while k>0:
        for p in xtemp:
            a1=abs(p-X[k])
            a2=abs(p+X[k])
            if a1==T[k-1]:
                return True
            elif a1 < T[k-1]:
                xtemp2.append(a1)
            if a2==T[k-1]:
                return True
            elif a2 < T[k-1]:
                xtemp2.append(a2)
        xtemp = xtemp2.copy()
        if len(xtemp)==0:
            return False
        k -= 1
    return -1

s=input()
x0=0
while x0 < len(s):
    if s[x0]=='F':
        x0 += 1
    else:
        break
    
q = x0+1
X = []
Y = []
torig=1
p=0
while q < len(s):
    if s[q]=='T':
        if torig==1:
            if p > 0:
                Y.append(p)
                torig=0
                p=0
            else:
                torig=0
                p=0
        else:
            if p>0:
                X.append(p)
                torig=1
                p=0
            else:
                torig=1
                p=0
        q+=1
    else:
        p+=1
        q+=1
if p > 0:
    if torig==1:
        Y.append(p)
    else:
        X.append(p)
X.sort()
Y.sort()
x, y = map(int,input().split(' '))
x -= x0
xx=F(X,abs(x))
yy=F(Y,abs(y))
if xx==-1 or yy==-1:
    print('something wrong')
elif xx==True and yy==True:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
def tot(X):
    p=0
    i=0
    ret=[]
    while i < len(X):
        p += X[i]
        ret.append(p)
        i+=1
    return ret

def F(X,x):
    if len(X)==0:
        if x == 0:
            return True
        else:
            return False
    elif len(X)==1:
        if X[0]==x:
            return True
        else:
            return False
    k=len(X)-1
    xtemp=[x]
    xtemp2 = []
    T = tot(X)
    while k>0:
        for p in xtemp:
            a1=abs(p-X[k])
            a2=abs(p+X[k])
            if a1==T[k-1]:
                return True
            elif a1 < T[k-1]:
                xtemp2.append(a1)
            if a2==T[k-1]:
                return True
            elif a2 < T[k-1]:
                xtemp2.append(a2)
        xtemp = xtemp2.copy()
        if len(xtemp)==0:
            return False
        k -= 1
    return -1

s=input()
x0=0
while x0 < len(s):
    if s[x0]=='F':
        x0 += 1
    else:
        break
    
q = x0+1
X = []
Y = []
torig=1
p=0
while q < len(s):
    if s[q]=='T':
        if torig==1:
            if p > 0:
                Y.append(p)
                torig=0
                p=0
            else:
                torig=0
                p=0
        else:
            if p>0:
                X.append(p)
                torig=1
                p=0
            else:
                torig=1
                p=0
        q+=1
    else:
        p+=1
        q+=1
if p > 0:
    if torig==1:
        Y.append(p)
    else:
        X.append(p)
X.sort()
Y.sort()
x, y = map(int,input().split(' '))
x -= x0
xx=F(X,abs(x))
yy=F(Y,abs(y))
if xx==-1 or yy==-1:
    print('something wrong')
elif xx==True and yy==True:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = str(input())
x,y = map(int, input().split())
y = abs(y)
a = 0
b = 0
adjust = 0
forward = 1
flag = "Yes"
if(s[0] == "F"):
    adjust = 2
for i in range(0,int(len(s))):
    if s[i] == "F":
        if forward == 1:
            a += 1
        else:
            b += 1
    else:
        forward *= -1
if (x >= 0 and a < x) or (x < 0 and a-adjust < -x):
    flag = "No"
x = abs(x)
if (a%2 != x%2 or b < y or b%2 != y%2):
    flag = "No"
print(flag)

Submission status: Wrong Answer

Solution code:
s = str(input())
x,y = map(int, input().split())
y = abs(y)
a = 0
b = 0
adjust = 0
forward = 1
flag = "Yes"
for i in range(0,int(len(s))):
    if s[i] == "F":
        if i == 0:
            adjust = 2
        if forward == 1:
            a += 1
        else:
            b += 1
    else:
        forward *= -1
if (x >= 0 and a < x) or (x < 0 and a-adjust < -x):
    flag = "No"
if (a%2 != abs(x)%2 or b < y or b%2 != y%2):
    flag = "No"
print(flag)

Submission status: Wrong Answer

Solution code:
s = str(input())
x,y = map(int, input().split())
y = abs(y)
a = 0
b = 0
adjust = 0
forward = 1
flag = "Yes"
for i in range(0,int(len(s))):
    if s[i] == "F":
        if forward == 1:
            a += 1
        else:
            b += 1
    else:
        forward *= -1
if(s[1] == "F"):
    adjust = 2
if (x >= 0 and a < x) or (x < 0 and a-adjust < -x):
    flag = "No"
x = abs(x)
if (a%2 != x%2 or b < y or b%2 != y%2):
    flag = "No"
print(flag)

Submission status: Wrong Answer

Solution code:
s = str(input())
x,y = map(int, input().split())
y = abs(y)
a = 0
b = 0
forward = 1
flag = "Yes"
for i in range(0,int(len(s))):
    if s[i] == "F":
        if forward == 1:
            a += 1
        else:
            b += 1
    else:
        forward *= -1
if (x >= 0 and a < x) or (x < 0 and a-2 < -x):
    flag = "No"
x = abs(x)
if (a%2 != x%2 or b < y or b%2 != y%2):
    flag = "No"
print(flag)

Submission status: Wrong Answer

Solution code:
s = str(input())
x,y = map(int, input().split())
y = abs(y)
a = 0
b = 0
forward = 1
flag = "Yes"
for i in range(1,int(len(s))):
    if s[i] == "F":
        if forward == 1:
            a += 1
        else:
            b += 1
    else:
        forward *= -1
if (x >= 0 and a < x) or (x < 0 and a-2 > -x):
    flag = "No"
if (a%2 != x%2 or b < y or b%2 != y%2):
    flag = "No"
print(flag)

Submission status: Wrong Answer

Solution code:
s = str(input())
x,y = map(int, input().split())
x = abs(x)
y = abs(y)
a = 0
b = 0
forward = 1
flag = "Yes"
for i in range(0,int(len(s))):
    if s[i] == "F":
        if forward == 1:
            a += 1
        else:
            b += 1
    else:
        forward *= -1
if (a < x or a%2 != x%2 or b < y or b%2 != y%2):
    flag = "No"
print(flag)

Submission status: Wrong Answer

Solution code:
def go(x,y,s,fw,g):
    if s is 'F':
        if fw == 1:
            x += 1
        elif fw == 2:
            y -= 1
        elif fw == 3:
            x -= 1
        else:
            y += 1
    else:
        if fw == 1 or fw == 3:
            if g[1] <= y:
                fw = 2
            else:
                fw = 0
        else:
            if g[0] <= x:
                fw = 3
            else:
                fw = 1
    return [x,y,fw]





S = input()
g = list(map(int,input().split()))
x,y,fw = 0,0,1
for i in range(len(S)):
    road = go(x,y,S[i],fw,g)
    x = road[0]
    y = road[1]
    fw = road[2]
if x == g[0] and y == g[1]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = input()
x,y=map(int,input().split())
fst = True;xory=1;xc=0;yc=0;xlis=[];ylis=[0];
for c in s:
    if c == "F":
        if xory == 1:
            xc +=1
        else:
            yc +=1
    else:
        if fst and xory ==1:
            xlis.append(xc)
            fst = False
            xory -=1
            xc = 0
        elif xory == 1:
            kari = xlis
            xlis =[i+xc for i in kari]
            xlis.extend([i-xc for i in kari])
            xc = 0
            xory -=1
        else:
            kari = ylis
            ylis = [i+yc for i in kari]
            ylis.extend([i-yc for i in kari])
            yc = 0
            xory +=1
if xory == 1:
    kari = xlis
    xlis =[i+xc for i in kari]
    xlis.extend([i-xc for i in kari])
    xc = 0
else:
    kari = ylis
    ylis = [i+yc for i in kari]
    ylis.extend([i-yc for i in kari])
    yc = 0

if x in xlis and y in ylis:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import math

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

sn=[]

for i in range(len(s)):
    sn.append(len(s[i]))

x = x-sn[0]
sx = []
sy = []
# 配列をx軸とy軸に分割
if len(sn) >= 3:
    sy = sn[1::2]
    sx = sn[2::2]
elif len(sn) == 2:
    sy.append(sn[1])
    sx.append(0)
else:
    sy.append(0)
    sx.append(0)

xsig = 0
ysig = 0

# x軸について
tarX = x

sx.sort()
sx.reverse()
for i in range(len(sx)):
    if tarX >= sx[i]:
        tarX -= sx[i]
    else:
        tarX += sx[i]

if tarX == 0:
    xsig = 1 

# y軸について
tarY = y
sy.sort()
sy.reverse()
for i in range(len(sy)):
    if tarY >= sy[i]:
        tarY -= sy[i]
    else:
        tarY += sy[i]

if tarY == 0:
    ysig = 1 


# print(tarX)
# print(tarY)

if xsig == 1 and ysig == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import math

s=list(input().split('T'))
sn=[]

for i in range(len(s)):
    sn.append(len(s[i]))

x, y = map(int,input().split(' '))
x = x-sn[0]

snx=[]
sny=[]

for i in range(2,len(sn),2):
    snx.append(sn[i])

for i in range(1,len(sn),2):
    sny.append(sn[i])

#X軸判定
xflg = 0
ansx=[]
prex=[0]
tmpx=set()
for i in range(len(snx)):
    tmpx=set()
    for j in prex:
        tmpx.add(j+snx[i])
        tmpx.add(j-snx[i])
    prex=tmpx

if x in tmpx:
    xflg = 1

#y軸判定
yflg = 0
prey=[0]
tmpy=set()
for i in range(len(sny)):
    tmpy=set()
    for j in prey:
        tmpy.add(j+sny[i])
        tmpy.add(j-sny[i])
    prey=tmpy

if y in tmpy:
    yflg = 1

if xflg == 1 and yflg == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s=input();xory="x";fst=True;xlist=[];ylist=[0];xc=0;yc=0

def plus(a,b):
    return a+b
def minus(a,b):
    return a-b

for t in s:
    if t == "T":
        if xory == "x":
            if fst:
                xlist.append(xc)
                fst = False
            else:
                new = [x+xc for x in xlist]
                new.extend([x-xc for x in xlist])
                xlist = new
            xory = "y"
            xc = 0
        elif xory == "y":
            new = [x+yc for x in ylist]
            new.extend([x-yc for x in ylist])
            ylist = new
            xory = "x"
            yc = 0
    elif t == "F":
        if xory == "x":
            xc+=1
        elif xory == "y":
            yc+=1

if xory == "x":
    new = [x+xc for x in xlist]
    new.extend([x-xc for x in xlist])
    xlist = new
elif xory == "y":
    new = [x+yc for x in ylist]
    new.extend([x-yc for x in ylist])
    ylist = new

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

if x in xlist and y in ylist:
    print("Yes")
else:
    print("No")